3D to 2D projections: A Camera

bewegung includes a pin-hole camera for simple 3D to 2D projections. In a nutshell, the a bewegung.Camera object can convert a bewegung.Vector3D object into a bewegung.Vector2D object given a location and direction in 3D space, i.e. the 3D vector is projected into a plane in 2D space. Because the “camera” is actually not a rendering system on its own, it simply adds meta data (bewegung.Vector.meta) to the returned 2D vector: The absolute distance (meta["dist"]) from the “pinhole” in 3D space to the vector in 3D space. This allows to (manually) implement various kinds of depth perception, e.g. backgrounds and foregrounds, in visualizations. The camera is a useful tool if e.g. multiple drawing backends are combined within a single animation and some kind of common 3D visualization is required. A typical combination is datashader for density distributions and cairo for annotations on top, see gallery for examples.

class bewegung.Camera(position=None, direction=None, roll=0.0, planeOffset=None, planeFactor=1.0, planeYFlip=False)

A virtual camera for 3D to 2D projections. 3D vectors are projected onto a 2D plane and returned combined with the absolute distance to the camera in 3D space. Vector arrays can be handled if numpy and numba are present.

Mutable.

Parameters
  • position (Optional[Vector3D]) – Position in 3D space

  • direction (Optional[Vector3D]) – Direction of view in 3D space

  • roll (float) – Roll angle in radians

  • planeOffset (Optional[Vector2D]) – Center offset of 2D plane

  • planeFactor (float) – Scaling factor for the 2D plane

  • planeYFlip (bool) – Allows to invert y-axes of 2D plane, i.e. switch to positive downwards

property direction: bewegung.linalg._single3d.Vector3D

Direction of view in 3D space

Return type

Vector3D

get_point(point3D)

Projects a 3D vector onto a 2D plane. Returns a 2D vector combined with the absolute distance to the camera in 3D space (meta["dist"]).

Parameters

point3D (Vector3D) – point in 3D space

Return type

Vector2D

get_points(points3d)

Projects a 3D vector array onto a 2D plane. Returns a 2D vector array combined with the absolute distances to the camera in 3D space (meta["dist"]).

Parameters

points3d (VectorArray3D) – points in 3D space

Return type

VectorArray2D

property planeFactor: float

Scaling factor for the 2D plane

Return type

float

property planeOffset: bewegung.linalg._single2d.Vector2D

Center offset of 2D plane

Return type

Vector2D

property planeYFlip: bool

Allows to invert y-axes of 2D plane, i.e. switch to positive downwards

Return type

bool

property position: bewegung.linalg._single3d.Vector3D

Position in 3D space

Return type

Vector3D

property roll: float

Roll angle in radians

Return type

float