Math Playground
Back to Graphics

Graphics › Start here

Homogeneous coordinates

Add a 4th number, w, to every 3D point. Suddenly translation, rotation, scale — and even perspective — are all just one 4×4 matrix multiply.

3D transform — scale, rotate, translate a cube
xyz

model matrix M = T · Ry · Rx · S

0.490.000.341.50
0.000.600.000.40
-0.340.000.490.00
0.000.000.001.00

The dashed cube is the original; the solid one is M applied to it. Order matters — scale then rotate then translate is the usual recipe (read the matrices right-to-left).

The problem with 3×3

A 3×3 matrix can rotate and scale a 3D vector, but it cannot translate it — multiplying by a matrix always sends the origin to the origin. Graphics needs translation in the same uniform machinery as everything else. The fix: work in 4D.

The trick

Write a 3D point (x, y, z) as the 4-vector (x, y, z, 1). Now a 4×4 matrix whose last column is (tx, ty, tz, 1) adds that offset — translation becomes a matrix multiply. Stack it with rotation and scale and you get one model matrix.

Points vs directions: it's the w

w = 1 → a position: translation moves it. w = 0 → a direction (a normal, a light ray): translation leaves it alone, exactly as it should. Same matrix, different w, correct behaviour for free.

And w earns its keep again: the perspective divide

The projection matrix deliberately writes something into w that depends on depth. After the multiply you divide x, y, z by that w — the perspective divide — and thatis what makes distant things small. One extra coordinate, and the whole pipeline collapses into “multiply by a 4×4, then ÷ w”.

The bigger picture

Homogeneous coordinates come from projective geometry: (x, y, z, w) and (kx, ky, kz, kw) are the same point. Parallel lines “meet at infinity” (w = 0) — which is precisely the vanishing point you see in a perspective image.