On this page
A 2×2 matrix can rotate or scale a point, but never slide it: any 2×2 matrix sends (0, 0) to (0, 0). Homogeneous coordinates add one number that makes translation a matrix too, and the same number later gives 3D graphics its perspective.
What are homogeneous coordinates?
Homogeneous coordinates are a coordinate system for projective geometry, introduced by August Ferdinand Möbius in his 1827 work Der barycentrische Calcul (Wikipedia: Homogeneous coordinates). That book also introduced the weighted-average idea in our post on barycentric coordinates of a triangle.
The rule for the plane fits in two lines:
Write the point (x, y) as (x, y, 1).
Read any triple (X, Y, W) with W ≠ 0 as the point (X/W, Y/W).
So (2, 1, 1) and (4, 2, 2) are the same point: multiplying all three numbers by the same non-zero number does not move it.
How do translate, rotate and scale become 3×3 matrices?
Rows are separated by semicolons.
Translate by (a, b): T = [1 0 a; 0 1 b; 0 0 1]
Rotate by θ about the origin: R = [cos θ −sin θ 0; sin θ cos θ 0; 0 0 1]
Scale by sx and sy: S = [sx 0 0; 0 sy 0; 0 0 1]
T times (x, y, 1) gives (x + a, y + b, 1): the translation sits in the third column and acts because the last coordinate is 1. Here is each matrix applied on its own to P = (2, 1), written (2, 1, 1):
Translate by (3, 1): (5, 2, 1).
Rotate by 90° (cos θ = 0, sin θ = 1): (−1, 2, 1).
Scale by 2: (4, 2, 1).
Why does the order of transformation matrices matter?
A product of matrices acts from right to left: in T·R·P the rotation touches P first. Take T for (3, 1) and R for 90°.
T·R = [0 −1 3; 1 0 1; 0 0 1] sends P to (2, 3): rotate, then shift.
R·T = [0 −1 −1; 1 0 3; 0 0 1] sends P to (−2, 5): shift to (5, 2), then rotate about the origin.
Matrix multiplication is not commutative; the picture at the top shows a whole triangle going both ways.
Rotation about a point c is T(c)·R·T(−c): move c to the origin, rotate, move back. Rotating P by 90° about (1, 1) gives (1, 0), then (0, 1), then (1, 2). For why a matrix is "where the basis vectors go", our change of basis matrix walkthrough builds that from a 2×2 example.
What is a point at infinity (w = 0)?
A triple with W = 0, such as (1, 2, 0), cannot be divided out to a point of the plane; it names a direction, and homogeneous coordinates give such points at infinity finite coordinates (Wikipedia: Homogeneous coordinates).
Translation ignores it: T·(1, 2, 0) = (1, 2, 0). Moving a car does not change which way it faces, so directions take W = 0 and positions W = 1.
Parallel lines meet there. Write the line ax + by + cW = 0 as the triple (a, b, c). The parallel lines y = 2x and y = 2x + 1 become (2, −1, 0) and (2, −1, 1). Their cross product, (−1, −2, 0), is where they meet: a point at infinity in the direction (1, 2), the direction both lines run in.
With these points added, any two distinct lines meet in exactly one point, as in the Fano plane and finite projective geometry.
How does the perspective divide work in 3D graphics?
In 3D the same trick uses four numbers (x, y, z, w) and 4×4 matrices. Web browsers use the idea too: the W3C specification for CSS transforms says each transform function "can get represented by a corresponding 4x4 matrix" (CSS Transforms Module Level 1).
The projection matrix copies depth into w. In Song Ho Ahn's derivation of the OpenGL projection matrix, the clip-space w is set to −z of the point in eye space, so the matrix's last row is (0, 0, −1, 0), and the clip coordinates become normalized device coordinates by dividing by w (OpenGL Projection Matrix). That division is the perspective divide.
A stripped-down projection that keeps x and y and uses that last row, so w = −z, shows the effect:
(2, 1, −4, 1) gets w = 4 and lands at (0.5, 0.25).
(4, 2, −8, 1) also lands at (0.5, 0.25): points on one ray from the eye hit the same spot.
(2, 1, −8, 1) lands at (0.25, 0.125): twice as far, half as far from the centre.
Far things look smaller, from one division. The full OpenGL matrix also fits the viewing frustum into a cube with depth from −1 to 1, as Song Ho Ahn's page derives.
To practise, build T·R and R·T for the triangle (1, 0), (3, 0), (2, 1) and check you get the coloured triangles in the picture above. If a step leans on an idea you have not met yet, the Fermi Concept Library gives every concept in mathematics and computing its own lesson and its place in the map. To check your matrix products line by line, the Fermi Problem Library has a step-by-step solver that explains the reasoning.



