Camera geometry · ten diagrams

Where does the ray hit?

A pixel tells us which way to look. A plane tells us where to stop. Find the hit by measuring how quickly the ray closes the gap to the plane.

One example: The camera is at O. X points right and the optical axis Z points forward (up on the page). Each spatial diagram shows the Y = 0 slice, with coordinates in the order (X, Z).

The fitted plane is the wall X = 1 m. A vertical line represents its trace in this slice. Diagram 06 puts the measurements on a number line instead.

01 A pixel picks a ray

A pixel to the right of the image center selects a ray tilted to the right of the optical axis. O X Z · optical axis ray through pixel selected pixel image slice at Z = 1 m

The ray starts at the camera and passes through the pixel's location on a virtual image plane. A pixel alone does not tell you how far along the ray to go.

Here: the pixel is at (0.5, 1) m on the image slice.

02 Give the ray one metre of forward depth

One ray step moves 0.5 metres right and 1 metre forward. The diagonal is longer than 1 metre. O X Z 1 m forward 0.5 m right Q = (0.5, 1) m one q-step

Move 1 m forward along Z and 0.5 m right along X. The combined move follows the ray. Its length is about 1.12 m, not 1 m.

q = (0.5, 1) is the direction per metre of forward depth. Its Z component is 1, but q is not a unit vector.

03 Pin down the plane

The wall X equals 1 metre contains P zero at (1, 3) and P one at (1, 1). Its unit normal points right at a right angle to the wall. O X Z wall X = 1 m P₀ = (1, 3) m P₁ = (1, 1) m n = (1, 0) · unit normal

Pick any point on the plane, such as P₀. It need not be the point the ray hits. The unit normal n has length 1 and points perpendicular to the plane.

P₀ and P₁ are on the same plane: both have X = 1 m.

04 Read the straight-across gap

Projecting the camera-to-P-zero arrow onto the normal gives F at (1, 0), the nearest point to the camera. The diagonal to P zero is longer. O X Z P₀ = (1, 3) m dashed: distance to P₀ F = (1, 0) m signed gap +1 m

Draw an arrow from the camera centre O to P₀. Now keep only the part that goes across the wall, at a right angle to it. In this picture, P₀ = (1, 3) m: 1 m right and 3 m forward. The unit normal n = (1, 0) points right, so the 3 m forward does not count. The projected arrow ends at F = (1, 0) m, the closest point on the wall.

n · P₀ is the signed component of that arrow (P₀'s position vector) along the unit normal. The arrow is measured in camera coordinates, and its component has the same length units (metres). Positive means along n; negative means opposite n. Drop the sign: |n · P₀| is the perpendicular, shortest distance from the camera to the plane.

n · P₀ = 1 × (1 m) + 0 × (3 m) = +1 m.The wall is |n · P₀| = 1 m away. That's not the straight-line distance to P₀ (‖P₀‖ = √10 m) or the distance along the ray.

05 Read how much the ray closes the gap

A ray step from O to Q projects to half a metre on the positive normal axis. The forward component is one metre. O Z Q = (0.5, 1) m 1 m forward +0.5 m along n X, along +n

Keep only the part of one q-step that goes in the normal direction. The step gains 0.5 m along +n for each metre of forward depth.

n · q = 1 × 0.5 + 0 × 1 = +0.5 metres of normal movement per metre of forward depth (m/m).

06 Divide gap by progress

On a normal-coordinate number line, two successive gains of half a metre reach the one-metre wall offset. +1 m gap to wall +0.5 m +0.5 m from 1 m forward from 1 m forward 0 0.5 1 normal coordinate n · P (m) · not Z

At the hit, the ray has gained exactly the normal offset of the wall. Divide that signed offset by the signed gain per metre of forward depth.

Signed gap: n · P₀ = +1 mRate of gain: n · q = +0.5 m/mForward depth: t = (n · P₀) / (n · q) = (+1 m) / (+0.5 m/m) = 2 m

The arrows each show the gain from one metre forward. The result is a depth in metres, not a count. It can be fractional.

07 Put the hit back on the ray

Scale the ray direction by 2 metres. It passes through Q at (0.5, 1) and hits the wall at P, (1, 2). O X Z 2 m 1 m wall X = 1 m P = (1, 2) m Q = (0.5, 1) m

Multiply both components of q by the depth. The result is 1 m right and 2 m forward, so the point is on both the ray and the wall.

P = t q = (2 m)(0.5, 1) = (1, 2) m.

08 Flip the normal, keep the same hit

Right-pointing n and left-pointing minus n give opposite signs, but the ray and wall still meet at the same point P. O X Z same hit P −n n

With the normal pointing left, the wall offset is negative. The ray also moves opposite that normal. Both signs change and cancel in the division.

t = (−1 m) / (−0.5 m/m) = 2 m with −n, the same depth as with n.

09 Watch near-parallel rays

A dashed parallel ray follows the optical axis and never hits the wall. A slightly tilted ray hits the same wall at 10 metres of forward depth. O X Z 10 m parallel q = (0, 1) hit at (1, 10) m near parallel q = (0.1, 1) same wall X = 1 m

The parallel ray makes no progress toward this wall, so it never hits it. The near-parallel ray makes little progress, so a small direction error can change the hit depth a lot.

Parallel: n · q = 0; no hit on this wall.Near parallel: t = (1 m) / (0.1 m/m) = 10 m.

Nearly parallel intersections can be unstable. If the line intersection gives t < 0, it is behind the camera and not on the forward ray.

10 Tell the three distances apart

A right triangle separates the 1-metre perpendicular wall gap, the 2-metre vertical Z-depth, and the 2.24-metre diagonal camera-to-hit range. O X Z Z-depth 2 m P = (1, 2) m ray distance ≈ 2.24 m wall gap = 1 m

The gap gets you across to the plane. Z-depth gets you as far forward as the hit. Ray distance goes directly from the camera to the hit.

Range = ‖P‖ = √5 m ≈ 2.24 m. The right triangle has legs of 1 m and 2 m.