Skip to content

Reference

Optics

Pinhole camera frusta and stereo rigs.

import { ... } from 'cseen/optics';

A pinhole camera with its image plane and rays.

function frustum(o?: FrustumOpts): Frustum
ParameterType
o?FrustumOpts

Returns Frustum

Options: FrustumOpts

Example

import { Scene, box, ground } from 'cseen';
import { frustum } from 'cseen/optics';
const s = new Scene({ view: { yaw: 62, pitch: 22 } });
s.add(ground(), box({ at: [1.4, 5, 0], size: [1, 1, 1.4], role: 'faint' }));
s.add(frustum({ at: [-1, -1, 1.6], target: [0.4, 5, 0.6], f: 1.6, fov: 46, depth: 4.6, labels: true }));
Run it in the playground →

Two cameras looking at one point: the picture behind stereo vision and depth from disparity.

function stereoRig(o?: StereoOpts): StereoRig
ParameterType
o?StereoOpts

Returns StereoRig

Options: StereoOpts

Example

import { Scene, ground } from 'cseen';
import { stereoRig } from 'cseen/optics';
const s = new Scene({ view: { yaw: 20, pitch: 55 } });
s.add(ground(), stereoRig({ baseline: 2.4, f: 1.5, point: [0.4, 4.2, 0.5] }));
Run it in the playground →

The classic picture of a pinhole camera: the centre, the image plane at focal length f, the rays through its corners and the optical axis. Give it points and it projects them. f and fov animate.

new Frustum(o?: FrustumOpts): Frustum

Options: FrustumOpts

Extends Node.

MemberDescription
o: FrustumOpts
centre(): (): V3the camera centre, as an anchor that follows the node
project(P: V3): V3 | nullwhere a point (in the node’s space) lands on the image plane, in world space, or null if behind the camera
collect(out: Prim[]): voidappends what this node draws right now to out, in world coordinates. Draws nothing when fully transparent.

Two parallel cameras a baseline apart looking at one point: both image planes, both rays, the horizontal epipolar lines, and the depth Z = f * b / d. baseline, f, fov and point animate, so you can watch the disparity shrink as the point moves away.

new StereoRig(o?: StereoOpts): StereoRig

Options: StereoOpts

Extends Node.

MemberDescription
o: StereoOpts
disparity(): numberdisparity: how far apart the two image points are along x, in world units. The depth is f * b / disparity.
depth(): numberthe depth recovered from the disparity, f * b / d. It equals the point’s distance from the baseline.
collect(out: Prim[]): voidappends what this node draws right now to out, in world coordinates. Draws nothing when fully transparent.

Options of frustum.

Extends NodeOpts.

OptionTypeDefaultDescription
target?V3the point the camera looks at, in the node’s space. Default: straight ahead along +y.
f?numberfocal length: how far the image plane is from the camera centre. Animatable.
fov?numbervertical field of view in degrees. Sets the size of the image plane. Animatable.
aspect?numberwidth over height of the image plane
depth?numberhow far the rays reach
points?Point[]points to project. A plain [x, y, z] is in the camera’s own space; a node or an anchor is wherever it is in the scene, and follows when either moves. Each gets a ray to the camera and a dot where it lands on the image plane
far?booleandraw the far end of the pyramid too
labels?booleanwrite C, f, and the name of the image plane
epipolar?booleandraw a horizontal line across the image plane through each projected point (the epipolar line of a rectified pair)
roll?numbertilt the camera about its own axis, in degrees
role?stringcolour role (ink, faint, accent, s1 to s8) or a role you define in CSS

Options of stereoRig.

Extends NodeOpts.

OptionTypeDefaultDescription
baseline?numberdistance between the two cameras. Animatable.
f?numberfocal length of both cameras
fov?numbervertical field of view in degrees
aspect?numberwidth over height of the image planes
point?V3the point both cameras see, in the rig’s space. Animatable.
depth?numberhow far the rays reach
labels?booleanwrite the names of the parts
role?stringcolour role (ink, faint, accent, s1 to s8) or a role you define in CSS