Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Perspective projection and vanishing points

Notes on the pinhole (perspective) projection model: how 3D points map to a 2D image plane, the projection matrix, and how parallel lines produce vanishing points and the horizon line.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Perspective projection is the mathematical model used to draw a realistic 3D scene on a 2D surface. Engineers use it in rendering (OpenGL/DirectX), camera modelling, augmented reality, and in computer vision for mapping between 3D points and image pixels.

Key ideas

Start from first principles and simple definitions:

  • Projection: a mapping that takes points from 3D space and gives corresponding points on a 2D surface (the image). We mean geometric projection, not printing or rasterization.
  • Center of projection (COP): the single point in space from which all projection rays originate. In the pinhole model the COP is the pinhole itself (the camera centre).
  • Image plane (projection plane): the 2D plane where the rays from the COP intersect to form the image. Coordinate axes on this plane give the image coordinates.
  • Pinhole camera model (pinhole model): the idealised model where rays pass through a single point (the COP) and intersect an image plane at distance f from the COP. No lenses, no distortion.
  • Focal length (f): the perpendicular distance from the COP to the image plane. SI unit: metre (m). In cameras it is often given in millimetres; convert to metres for SI.
  • Principal point: the intersection of the optical axis (line through COP perpendicular to the image plane) with the image plane. Its coordinates are often (cx, cy) on the image.
  • Vanishing point: the image-plane point where a family of parallel lines in 3D (with a given direction) appear to converge. If the direction is d = (dx, dy, dz) and dz ≠ 0 (non-parallel to image plane), the vanishing point is finite; if dz = 0 it lies at infinity (no finite vanishing point on the image plane).
  • Horizon line: the set of vanishing points for all directions lying in a given plane (for example, the ground plane). For the ground plane this is the horizon line of the scene.

Coordinate setup and basic derivation (standard camera coordinates):

Assumptions: place the COP at the origin O = (0,0,0). Use a right-handed camera coordinate system where the optical axis is the Z-axis. Put the image plane at Z = f (a plane parallel to XY, in front of the camera). We assume object points have Z > 0 so they lie in front of the camera.

Let P = (X, Y, Z) be a point in 3D (world or camera coordinates — if world coordinates are used, we must first transform into camera coordinates). In general, given world coordinates X_w, camera-frame coordinates are X_c = R X_w + t with rotation R and translation t, and the full homogeneous projection is p_h ~ K [R | t] X_h (divide by the third component to get image coordinates). The ray from the COP through P is the set {t·(X,Y,Z) : t ≥ 0}. The intersection of that ray with the image plane Z = f occurs at t* such that t*·Z = f, so t* = f / Z. Therefore the image coordinates p = (x, y, f) satisfy:

x = t*·X = f·X / Z

y = f·Y / Z

This is the core perspective projection formula: image coordinates are proportional to the 3D coordinates scaled by f/Z.

Homogeneous coordinates and projection matrix (useful in computer graphics):

Represent a 3D point in homogeneous coordinates as (X, Y, Z, 1). The 3×4 camera projection matrix (simple pinhole, principal point at origin) is

P = [ [f, 0, 0, 0], [0, f, 0, 0], [0, 0, 1, 0] ]

Multiplying P by (X, Y, Z, 1)^T gives (fX, fY, Z)^T. Convert to inhomogeneous image coordinates by dividing by the third component Z, producing (fX/Z, fY/Z, 1). More generally, define the 3×3 intrinsic matrix K = [ [fx, s, cx], [0, fy, cy], [0, 0, 1] ] to encode pixel units and principal point; with extrinsics R (rotation) and t (translation), the full camera matrix is P = K [R | t].

Vanishing point derivation:

A family of parallel lines in 3D share a direction vector d = (dx, dy, dz). A representative line through a point Q = (X0, Y0, Z0) is Q + t·d. For large t, the point goes to infinity along direction d; the intersection of the line-of-sight with the image plane tends to the vanishing point. Substitute Q + t·d into the projection formula and take t → +∞:

x_vp = f·(X0 + t·dx) / (Z0 + t·dz) → f·dx / dz (if dz ≠ 0)

y_vp = f·(Y0 + t·dy) / (Z0 + t·dz) → f·dy / dz (if dz ≠ 0)

So the vanishing point for direction d is at (f·dx/dz, f·dy/dz) on the image plane. If dz = 0 (the direction vector is parallel to the image plane), the denominator does not grow and the vanishing point goes to infinity — i.e. no finite vanishing point. With pixel intrinsics (fx, fy, cx, cy) and zero skew, the pixel VP is (u_v, v_v) = (fx·dx/dz + cx, fy·dy/dz + cy).

Diagram you should draw for an exam (describe exactly):

  • Draw a 3D coordinate system with axes labelled X (right), Y (up), Z (forward). Place the COP at the origin O. Draw the image plane as a vertical rectangle parallel to the XY plane at Z = f; label its centre as the principal point (0,0,f).
  • Draw a 3D point P = (X,Y,Z) in front of the COP (Z > 0). Draw the ray from O through P and mark its intersection with the image plane as p = (x,y,f). Label X,Y,Z and x,y,f.
  • For vanishing point: draw a set of parallel lines in space with direction d, show one line intersecting the image plane at a point near where all these projections converge; mark that as VP and annotate the formula VP = (f dx/dz, f dy/dz).

State assumptions clearly (what examiners expect): COP at origin, image plane at Z = f, Z > 0 for visible points, negligible lens distortion.

Formulas

x = f * X / Z — x coordinate on image plane (m). Applies when COP at origin and image plane at Z = f. X: metre, Z: metre, f: metre.

y = f * Y / Z — y coordinate on image plane (m). Y: metre.

[f 0 0 0; 0 f 0 0; 0 0 1 0] * [X; Y; Z; 1] = [fX; fY; Z] — homogeneous matrix multiplication (3×4). After division by Z, image homogeneous coordinates are (fX/Z, fY/Z, 1).

vanishing point = ( x_v, y_v ) = ( f * dx / dz, f * dy / dz ) — given direction vector d = (dx, dy, dz) in camera coordinates, dz ≠ 0. Units: metres.

principal point offset: x = fX/Z + cx, y = fY/Z + cy — when the principal point is at (cx, cy) on the image plane. Units: metres.

Note: if you use pixel image coordinates, use fx, fy in pixels and principal point (cx, cy) in pixels, and keep X, Y, Z in a consistent length unit (e.g., metres); fx and fy are obtained from the physical focal length and pixel pitch. Do not convert X or Z to pixels.

Worked examples

Example 1 — Project a 3D point to the image plane

Given: focal length f = 50 mm = 0.050 m. A point in camera coordinates P = (X, Y, Z) = (2.0 m, 1.0 m, 5.0 m). Find image coordinates x, y in metres and millimetres.

Step 1: formula: x = f·X/Z, y = f·Y/Z.

Step 2: compute: x = 0.050 * 2.0 / 5.0 = 0.050 * 0.4 = 0.020 m.

y = 0.050 * 1.0 / 5.0 = 0.050 * 0.2 = 0.010 m.

Convert to mm: x = 20 mm, y = 10 mm.

Answer: image coordinates = (0.020 m, 0.010 m) on the plane Z = f (equivalently (20 mm, 10 mm)).

Example 2 — Vanishing point of a family of parallel lines

Given: focal length f = 50 mm = 0.050 m. Direction vector d = (dx, dy, dz) = (1.0, 0.5, 2.0) in camera coordinates. Find the vanishing point (x_v, y_v) on the image plane.

Step 1: formula: x_v = f·dx/dz, y_v = f·dy/dz.

Step 2: compute: x_v = 0.050 * 1.0 / 2.0 = 0.050 * 0.5 = 0.025 m (25 mm).

y_v = 0.050 * 0.5 / 2.0 = 0.050 * 0.25 = 0.0125 m (12.5 mm).

Answer: vanishing point = (0.025 m, 0.0125 m) or (25 mm, 12.5 mm) on the image plane.

(If dz = 0, state: no finite vanishing point; the lines remain parallel to the image plane and their projections are parallel.)

Common mistakes

  • Sign errors: different texts place the image plane at Z = -f; always state your sign convention. If you use Z = -f, formulas change sign; be consistent.
  • Units mismatch: using f in mm but X, Z in metres without converting.
  • Assuming every set of parallel lines has a finite vanishing point — if the direction vector has dz = 0 under your camera axis choice, the vanishing point is at infinity.
  • Confusing principal point offsets (cx, cy) with focal length; these shift the projection.

For your exam

Types of questions you will see from this topic:

  • Definitions: define pinhole model, COP, focal length, vanishing point, horizon line. Full marks: clear definitions and units where relevant.
  • Derivation: derive x = fX/Z and the homogeneous projection matrix. Full marks: draw the diagram, state assumptions (COP at origin, image plane at Z = f), show the t* step and division by Z, then give matrix form and explain homogeneous division.
  • Numerical problems: project a given 3D point with given f (include unit conversions), or compute vanishing point for a direction vector. Full marks: show formulas, substitute numbers with units, keep units consistent, final answer with correct units.
  • Diagrams: draw COP, image plane, a 3D point, the projecting ray, and label the intersection. For vanishing points, draw parallel lines and the VP. Full marks: neat labelling of axes, points, and plane positions.
  • Short notes: explain horizon line for a ground plane or discuss effect of moving the principal point. Full marks: definition, small derivation or formula, and a short diagram or example.

Always state your sign convention at the start of the answer.

Quick check

  1. If f = 0.04 m and P = (1.2 m, 0.6 m, 3.0 m), what is x?
  2. For direction d = (2, 0, 4) and f = 0.05 m, what is the vanishing point (x_v, y_v)?
  3. What happens to the projected image coordinates when Z doubles (keeping X,Y,f fixed)?

Answers: 1) x = 0.04 * 1.2 / 3.0 = 0.016 m. 2) x_v = 0.05 * 2 / 4 = 0.025 m, y_v = 0.05 * 0 / 4 = 0.0 m. 3) x and y halve (they scale as 1/Z).

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?