← Recreational maths

Lab · Projective geometry

Shadow Projection

A lamp, a card and its shadow: central projection as a 3 × 3 matrix.

Hold a card under a lamp and look at its shadow on the table. A square card casts a quadrilateral that is usually not a square: lengths, angles and parallel lines are all distorted. Yet straight edges stay straight. The applet below makes this exact. A point light $L$ projects a quadrilateral on a tilted plane $\pi_1$ onto the floor $\pi_2$, and the panel shows the $3 \times 3$ matrix that does it.

Drag the vertices or the light, change the tilt of $\pi_1$, and orbit the camera. Watch the dashed vanishing line: points of $\pi_1$ that sit level with the light cast shadows that run off to infinity. Then switch the light to At infinity (parallel), which models sunlight, and watch the vanishing line disappear.

Where this comes from: projective geometry

Shadows from a point source are central projections, the same operation a Renaissance painter uses to draw a tiled floor in perspective. Desargues studied these maps in the 17th century, and Poncelet's Traité des propriétés projectives des figures (1822) turned them into a subject: projective geometry studies exactly the properties of figures that survive projection.

What survives a projection

  • Lines and incidence. Lines go to lines, and a point on a line stays on that line.
  • Cross-ratio. For four points $A, B, C, D$ on a line, the number $\dfrac{AC \cdot BD}{BC \cdot AD}$ is unchanged, even though every individual length changes.
  • Not parallelism. Parallel lines on $\pi_1$ usually cast shadows that meet. The meeting point is the image of a "point at infinity", and all such points form the line at infinity.

Homogeneous coordinates

The clean way to handle points at infinity is to write a point $(u, v)$ of the plane as $(u : v : 1)$, a line through the origin in $\mathbb{R}^3$. Points $(u : v : 0)$ are the points at infinity. Every projection between planes is then a linear map $$\begin{pmatrix} x' \\ y' \\ w' \end{pmatrix} = M \begin{pmatrix} u \\ v \\ 1 \end{pmatrix}, \qquad (x, y) = \Big(\frac{x'}{w'}, \frac{y'}{w'}\Big),$$ with $M$ an invertible $3 \times 3$ matrix defined up to a scalar, which is an element of $\mathrm{PGL}(3, \mathbb{R})$. The applet scales $M$ so that $\det M = 1$. The bottom row of $M$ is the vanishing line: where $w' = 0$, the shadow is at infinity. When $\pi_1$ is parallel to the floor that row becomes $(0, 0, 1)$, and the shadow is just a scaled copy of the card.

A light at infinity

The sun is so far away that its rays are effectively parallel. Projectively this is not a new kind of light: it is a point light placed at a point at infinity, $L = (s_x : s_y : s_z : 0)$, where $s$ is the direction of the rays. The same formula for $M$ applies, but now its bottom row is $(0, 0, c)$. No finite point of $\pi_1$ is sent to infinity, so there is no vanishing line, and the shadow map is affine: parallel edges cast parallel shadows and midpoints go to midpoints. In general, the affine maps are exactly the projective maps that send the line at infinity to itself. Point lights give the full projective group; parallel light gives only its affine part.

How the matrix is computed

Here is exactly how the applet produces the matrix shown in its panel, for any choice of light and plane.

1. The plane $\pi_1$. With tilt $\alpha$, hinge angle $\beta$ and height $h$, the applet uses $$O = (0, 0, h), \quad e_1 = (\cos\beta,\ \sin\beta,\ 0), \quad e_2 = (-\sin\beta\cos\alpha,\ \cos\beta\cos\alpha,\ \sin\alpha).$$ The point with plane coordinates $(u, v)$ is $P = O + u\,e_1 + v\,e_2$. In homogeneous coordinates, $$\begin{pmatrix} P \\ 1 \end{pmatrix} = B \begin{pmatrix} u \\ v \\ 1 \end{pmatrix}, \qquad B = \begin{pmatrix} e_1 & e_2 & O \\ 0 & 0 & 1 \end{pmatrix} \quad (4 \times 3).$$

2. Casting the shadow. Write the light as $L = (L_x : L_y : L_z : L_w)$, with $L_w = 1$ for a point light and $L = (s_x : s_y : s_z : 0)$ for a light at infinity. The shadow of $X = (X_x : X_y : X_z : X_w)$ is where the line through $L$ and $X$ meets the floor. The point $L_z X - X_z L$ lies on that line and has $z$-coordinate $0$, so it is the shadow. Dropping the zero coordinate gives $$\Pi = \begin{pmatrix} L_z & 0 & -L_x & 0 \\ 0 & L_z & -L_y & 0 \\ 0 & 0 & -L_w & L_z \end{pmatrix} \quad (3 \times 4).$$

3. The raw matrix. Composing, $M_{\text{raw}} = \Pi B$: $$M_{\text{raw}} = \begin{pmatrix} L_z\cos\beta & -L_z\sin\beta\cos\alpha - L_x\sin\alpha & -L_x h \\ L_z\sin\beta & L_z\cos\beta\cos\alpha - L_y\sin\alpha & -L_y h \\ 0 & -L_w\sin\alpha & L_z - L_w h \end{pmatrix}.$$ The bottom row cuts out the vanishing line, the points with $w' = 0$. For a light at infinity ($L_w = 0$) it is $(0, 0, L_z)$, which is why parallel light always gives an affine map.

4. Normalising. With $n = e_1 \times e_2$ the unit normal of $\pi_1$, $$\det M_{\text{raw}} = L_z^2 \big( n \cdot (L_x, L_y, L_z) - L_w\, n \cdot O \big).$$ For a point light this is $L_z^2\, n \cdot (L - O)$, which vanishes exactly when the light lies on $\pi_1$. For parallel light it is $L_z^2\, n \cdot s$, which vanishes exactly when the rays run parallel to $\pi_1$. The applet sets $M = M_{\text{raw}} / \sqrt[3]{\det M_{\text{raw}}}$, using the real cube root, so $\det M = 1$. Rescaling does not change the projective map. In dimension $3$ the only scalar matrix of determinant $1$ is the identity, so $SL(3, \mathbb{R}) = PSL(3, \mathbb{R}) \cong PGL(3, \mathbb{R})$, and each shadow map has exactly one representative with determinant $1$. That is the matrix shown in the panel.

Worked example: the applet's starting position

$L = (2, 1, 5)$ (point light), $h = 2$, $\alpha = 25^\circ$, $\beta = 0^\circ$: $$M_{\text{raw}} = \begin{pmatrix} 5 & -0.84524 & -4 \\ 0 & 4.10892 & -2 \\ 0 & -0.42262 & 3 \end{pmatrix}, \qquad \det M_{\text{raw}} = 57.40763,$$ $$M = \begin{pmatrix} 1.29612 & -0.21911 & -1.03690 \\ 0 & 1.06513 & -0.51845 \\ 0 & -0.10955 & 0.77768 \end{pmatrix}.$$ These are the numbers the panel shows when the page first loads.

Why a quadrilateral

The fundamental theorem of projective geometry says that a projective map of the plane is determined by where it sends four points in general position, no three on a line. So the four corners of the card, together with their four shadows, pin down $M$ completely. That is why the applet uses a quadrilateral and not a triangle.

Further reading

  • H. S. M. Coxeter, Projective Geometry, 2nd ed., Springer, 1987.
  • J. Richter-Gebert, Perspectives on Projective Geometry, Springer, 2011.