Skip to main content

Derive perspective projection matrix

Short answer

Perspective projection maps a point P(x,y,z) to P'(xp,yp,zvp) on the view plane using xp = x·dp/(zprp−z), yp = y·dp/(zprp−z) where dp = zprp−zvp. The homogeneous matrix has row [1 0 0 0; 0 1 0 0; 0 0 -zvp/dp zvp·zprp/dp; 0 0 -1/dp zprp/dp] so that h = (zprp−z)/dp.

Derive the transformation matrix for perspective projection (derive an expression for perspective projection of a 3D point).

Setup: the centre of projection (COP) is on the z-axis at (0, 0, zprp). The view plane is z = zvp. Let dp = zprp − zvp. A point P(x, y, z) is projected to P'(xp, yp, zvp) where the line from the COP through P meets the view plane.

        y
        |        P(x,y,z)
        |      /
        |    /
   yp   |--/--- view plane (z = zvp)
        |/
 COP ---+----------------> z
      zprp

Derivation (similar triangles): along the line from the COP to P, any point is

x' = x·u, y' = y·u, z' = zprp − (zprp − z)·u, with 0 ≤ u ≤ 1

Put z' = zvp:

zvp = zprp − (zprp − z)u → u = (zprp − zvp)/(zprp − z) = dp/(zprp − z)

So

  • xp = x · dp/(zprp − z) = x / ((zprp − z)/dp)
  • yp = y · dp/(zprp − z)
  • zp = zvp

Matrix form: use homogeneous coordinates with h = (zprp − z)/dp, so that xp = x_h/h and yp = y_h/h.

| x_h |   | 1 0  0           0            | | x |
| y_h | = | 0 1  0           0            | | y |
| z_h |   | 0 0  -zvp/dp     zvp·zprp/dp  | | z |
| h   |   | 0 0  -1/dp       zprp/dp      | | 1 |

Check: h = −z/dp + zprp/dp = (zprp − z)/dp, and z_h/h = zvp·(zprp − z)/dp ÷ ((zprp − z)/dp) = zvp.

Special cases

  • View plane at z = 0 (zvp = 0): xp = x·zprp/(zprp − z), and the matrix has third row (0 0 0 0).
  • COP at the origin and view plane z = d: xp = x·d/z, yp = y·d/z.

Perspective makes distant objects smaller (perspective foreshortening). Points with z = zprp are projected to infinity (h = 0).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Graphics chapter 4 questions →