Search

Search papers and lessons

Homogeneous Coordinates

Level 2 · 8 min read

Homogeneous coordinates add one extra number to each point so that shifts, rotations and perspective all become matrix multiplications, and points that differ by a scale factor are treated as the same point.

On this page

  • Colour = topic mix
  • Linear algebra
  • Discrete math
  • Sign in to see your progress

TL;DR

A 2D point (x,y)(x, y) is written as the three numbers (x,y,1)(x, y, 1). Written this way, moving a point by a fixed offset is a matrix multiplication, just like rotating or scaling it. Two triples that are scalar multiples of each other, such as (2,4,2)(2, 4, 2) and (1,2,1)(1, 2, 1), name the same point.

Where you'll see it: computer graphics pipelines, camera and projection models such as the pinhole camera, and robotics code that chains many transforms.

Intuition

Suppose you want to move every point of a drawing 5 units to the right. A rotation about the origin can be written as a 2 by 2 matrix. A shift cannot. Multiplying a matrix by (x,y)(x, y) always gives (0,0)(0, 0) when the input is (0,0)(0, 0), so the origin never moves. A shift has to move the origin, and that is impossible for a linear map of R2\mathbb{R}^2.

The trick is to add one more coordinate. Imagine the plane z=1z = 1 floating in three-dimensional space, and identify each point (x,y)(x, y) with the 3D point (x,y,1)(x, y, 1) on that plane. Now a shift is a linear map in three dimensions. It is a shear of the plane, so the origin of the flat picture moves, but in 3D the transformation is still linear.

The extra coordinate also carries a second meaning. If you scale a 3D vector (x,y,w)(x, y, w) by a nonzero number, you get the same point on the plane, because you divide by ww to recover the flat coordinates. So (x,y,w)(x, y, w) means the flat point (x/w,y/w)(x/w, y/w), and all its scalar multiples mean the same thing. This is what makes perspective projection work: a perspective camera divides by depth, and the division can be done in one step at the end.

flowchart LR
  P["Flat point (x, y)"] --> H["Homogeneous (x, y, 1)"]
  H --> M["Multiply by a 3x3 matrix"]
  M --> D["Divide by w to get flat (x', y')"]

The math

Definition

For a point (x,y)(x, y) in the plane, a homogeneous representation is any triple (X,Y,W)(X, Y, W) with W≠0W \neq 0 such that

x=XW,y=YWx = \frac{X}{W}, \qquad y = \frac{Y}{W}

Two triples (X,Y,W)(X, Y, W) and (cX,cY,cW)(cX, cY, cW) with c≠0c \neq 0 represent the same point. The standard representative has W=1W = 1, which is why you append a 1 to a point.

Triples with W=0W = 0 are called points at infinity. They represent directions rather than locations. For example, (1,0,0)(1, 0, 0) is the point at infinity in the direction of the positive xx-axis, where every horizontal line meets "at infinity". Dividing by WW is not possible, which is why these points have no flat counterpart.

Translations as matrices

A 2D affine map sends (x,y)(x, y) to (ax+by+tx,  cx+dy+ty)(a x + b y + t_x,\; c x + d y + t_y). In homogeneous form, this is one matrix product:

(x′y′1)=(abtxcdty001)(xy1)\begin{pmatrix} x' \\ y' \\ 1 \end{pmatrix} = \begin{pmatrix} a & b & t_x \\ c & d & t_y \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x \\ y \\ 1 \end{pmatrix}

The top-left 2×22 \times 2 block is the linear part (rotation, scale, shear). The last column holds the translation. The bottom row (0,0,1)(0, 0, 1) keeps the WW coordinate at 1 for affine maps. Translation is a=d=1a = d = 1, b=c=0b = c = 0, with tx,tyt_x, t_y the shift.

Composition

If M1M_1 is applied first and then M2M_2, the combined map is M2M1M_2 M_1, computed once as a matrix product. This is why graphics engines store a single matrix per object and multiply them together. Order matters, as with any matrix product: rotating then translating is not the same as translating then rotating.

Directions versus points

A direction vector has W=0W = 0. Multiplying it by the translation matrix leaves it unchanged, because the translation column is multiplied by zero. That is the right behaviour: moving a vector does not change its direction or length. Rotation and scale still act on directions, so one matrix formula handles both points and vectors.

Worked examples

Example
Shift a point by a matrix

Move the point (2,3)(2, 3) by tx=5t_x = 5 and ty=−1t_y = -1.

  1. Write the point as (2,3,1)(2, 3, 1).
  2. Build the translation matrix (10501−1001)\begin{pmatrix} 1 & 0 & 5 \\ 0 & 1 & -1 \\ 0 & 0 & 1 \end{pmatrix}.
  3. Multiply: the first row gives 1⋅2+0⋅3+5⋅1=71 \cdot 2 + 0 \cdot 3 + 5 \cdot 1 = 7. The second gives 0⋅2+1⋅3+(−1)⋅1=20 \cdot 2 + 1 \cdot 3 + (-1) \cdot 1 = 2. The third gives 11.
  4. Result: (7,2,1)(7, 2, 1), which is the flat point (7,2)(7, 2).

Interpretation: one matrix multiply moved the point, and no addition was written separately.

Example
Rotate then shift, combined into one matrix

Rotate 90∘90^\circ counterclockwise about the origin, then shift by (4,0)(4, 0). The rotation is R=(0−10100001)R = \begin{pmatrix} 0 & -1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{pmatrix} and the shift is T=(104010001)T = \begin{pmatrix} 1 & 0 & 4 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix}.

  1. Combine them: M=TRM = T R. Row 1 of TT is (1,0,4)(1, 0, 4), and multiplying by the columns of RR gives (0,−1,4)(0, -1, 4). Row 2 of TT is (0,1,0)(0, 1, 0), which gives (1,0,0)(1, 0, 0). Row 3 is (0,0,1)(0, 0, 1). So M=(0−14100001)M = \begin{pmatrix} 0 & -1 & 4 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{pmatrix}.
  2. Apply MM to (1,2,1)(1, 2, 1). The first coordinate is 0⋅1+(−1)⋅2+4⋅1=20 \cdot 1 + (-1) \cdot 2 + 4 \cdot 1 = 2. The second is 1⋅1+0⋅2+0⋅1=11 \cdot 1 + 0 \cdot 2 + 0 \cdot 1 = 1. The third is 11.
  3. Result: (2,1)(2, 1).
  4. Check by hand: rotating (1,2)(1, 2) by 90∘90^\circ counterclockwise gives (−2,1)(-2, 1). Shifting by (4,0)(4, 0) gives (2,1)(2, 1). They agree.

Interpretation: a whole chain of transforms can be stored as one 3×33 \times 3 matrix, and the hand check is a good way to catch a sign error.

Example
Scalar multiples name the same point

The triples (2,4,2)(2, 4, 2) and (1,2,1)(1, 2, 1) both give the flat point (2/2,4/2)=(1,2)(2/2, 4/2) = (1, 2) and (1/1,2/1)=(1,2)(1/1, 2/1) = (1, 2). Multiplying all three numbers by 2 leaves X/WX/W and Y/WY/W unchanged. So a homogeneous point is an equivalence class, and the scale is not meaningful on its own.

Tradeoffs and failure modes

SituationWhat goes wrongBetter choice
Plain 2 by 2 matrices for a scene with shiftsThe origin is fixed, so the shift cannot be expressedUse 3 by 3 homogeneous matrices
Forgetting to divide by WW at the endPoints are off by a scale factor, and the picture is wrongDivide by WW once, when leaving homogeneous form
Using W=1W = 1 for a directionThe direction gets shifted as if it were a pointUse W=0W = 0 for directions
Lots of transforms every frameRepeated per-point work adds upMultiply the matrices once, then apply the product to each point
Numerical error when WW is near zeroDivision blows up for points near infinityClip or handle points near infinity separately

The most common bug is mixing up the convention for points and vectors. A translation that moves the ground plane but also moves the lighting direction is almost always a WW mistake.

History

The idea comes from projective geometry in the 19th century, where coordinates are defined only up to a scale. Those coordinates let parallel lines meet at a point at infinity, which simplified many geometric statements. Computer graphics adopted the same representation to treat shifts, rotations and perspective in one framework. In 3D the analogue is a 4 by 4 matrix acting on (x,y,z,1)(x, y, z, 1), which is the form graphics pipelines use for perspective projection.

Check yourself

QuestionWhat is the homogeneous form of the point (3,−2)(3, -2), and which other triple also represents it?Show answer

The standard form is (3,−2,1)(3, -2, 1). The triple (6,−4,2)(6, -4, 2) also represents it, because it is the standard form scaled by 2, and dividing by W=2W = 2 gives (3,−2)(3, -2) again.

QuestionApply the translation by (tx,ty)=(−1,4)(t_x, t_y) = (-1, 4) to the point (5,0)(5, 0) using a homogeneous matrix. What is the result?Show answer

Write (5,0,1)(5, 0, 1) and multiply by (10−1014001)\begin{pmatrix} 1 & 0 & -1 \\ 0 & 1 & 4 \\ 0 & 0 & 1 \end{pmatrix}. The first row gives 5−1=45 - 1 = 4, the second gives 0+4=40 + 4 = 4, and the third is 1. The result is (4,4)(4, 4).

QuestionWhy does a direction vector use W=0W = 0, and what happens to it under a translation?Show answer

A direction describes which way to go, not where you are, so shifting it should leave it unchanged. Setting W=0W = 0 makes the translation column multiply by zero, so the direction is not shifted. The linear part still rotates or scales it, which is the behaviour you want.

QuestionYou compose a rotation RR and then a translation TT into M=TRM = TR. A colleague writes M=RTM = RT instead. Give a point where the two results differ, and explain why.Show answer

Take the point (1,0)(1, 0) with a 90∘90^\circ counterclockwise rotation RR and a shift TT by (4,0)(4, 0). Applying RR first and then TT: RR sends (1,0)(1, 0) to (0,1)(0, 1), and TT then gives (4,1)(4, 1). Applying TT first and then RR: TT sends (1,0)(1, 0) to (5,0)(5, 0), and RR then gives (0,5)(0, 5). The results (4,1)(4, 1) and (0,5)(0, 5) differ. Matrix multiplication is not commutative, so the order of the transforms matters, and TRTR and RTRT are different maps.

Sources