2D Transformations
Translate, rotate, scale, and shear as matrices, plus homogeneous coordinates and why composition order matters.
Every shape you see on screen is positioned, rotated, and resized by matrices. Graphics encodes these moves as affine transformations — operations that map straight lines to straight lines and keep parallel lines parallel. Pick an operation below and drag the sliders; the dashed outline is the original shape and the filled shape is the transformed result.
The dashed outline is the original; the filled shape is M applied to every vertex. The translation column (third column) only does anything because the point carries a 1 in its third slot.
The four basic transforms
A point becomes under a matrix. The matrix’s columns are where the basis vectors land:
- Scale: stretches each axis independently.
- Rotation: spins about the origin.
- Shear: slides points sideways in proportion to their height.
Scale, rotate, and shear all keep the origin fixed. Translation — sliding the whole shape — is the odd one out: it cannot be written as a matrix multiply, because moving the origin is not linear.
Homogeneous coordinates
The fix is to add a third coordinate that is always 1, turning a 2D point into and every transform into a matrix:
The extra column is the translation, and it only takes effect because the point carries that trailing 1. Now every affine move — including translation — is a single matrix multiply, which is exactly what GPUs are built to do fast.
Composition: order matters
Chaining transforms is just multiplying matrices. To rotate a shape and then translate it, you apply to each point — the rightmost matrix acts first. Because matrix multiplication is not commutative, . Rotate-then-translate swings the shape into place; translate-then-rotate orbits it around the origin instead. Toggle the compose checkbox above to see a second rotation stack on top of your transform.
Collapsing a long chain into one combined matrix is the standard trick: compute it once on the CPU, then apply that single matrix to thousands of vertices.
Takeaways
- Scale, rotation, and shear are matrices; their columns show where the basis vectors and go.
- Homogeneous coordinates add a constant 1 so translation becomes a matrix multiply like everything else.
- Transforms compose by matrix multiplication, and order matters: differs from .