01 A pixel picks a ray
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.
Camera geometry · ten diagrams
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.
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.
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.
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.
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.
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).
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
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.
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.
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.
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.