Skip to content

frame3d

Mojo module 🡭

frame3d

The 3D frame: data ranges to a centred unit cube, the cube through a Camera3D, and the projection fitted to a plot rect (#345).

The second of #345’s five steps. It owns the part of a 3D chart that is not the mark: where a data point lands on the page, and the box, ticks and labels that make the projection readable. Every 3D mark projects through this and then draws its own glyphs.

The cube is centred on the origin, each axis normalised to [-0.5, 0.5], before it is projected. Rotation is about the origin, so centring first is what makes the camera turn the scene rather than swing it around the page. It also means one axis spanning nanometres and another spanning kilometres come out the same size, which is the only sensible default – a 3D box is a viewing volume, not a shared unit.

The fit preserves aspect. The eight corners are projected, their bounding box measured, and one scale applied to both directions. Using the width and height ratios separately would stretch the cube to fill the rect, which shears a projection: a sphere would come out an ellipsoid and equal data steps along x and y would look unequal.

y is flipped exactly once, here, where every other mark’s y is flipped. Camera3D hands back camera-space y pointing up, like data; this is the one place it becomes a pixel row that grows downward.

Structs

  • Frame3D: A camera, the data extent it views, and the plot rect it draws into: everything needed to turn a data point into a pixel.