Application to Computer Graphics
Rotations, Scalings and Reflections as Matrices
Matrices as the working language of 2D graphics
In the linear 2D model used here, rotations, scalings, and reflections can be represented by 2 × 2 matrices acting on column vectors.
To include translation in the same matrix-multiplication framework, graphics systems use homogeneous coordinates. Because matrix multiplication composes, a whole chain of operations collapses into one matrix that can be applied once per vertex.
That is the entire reason graphics pipelines are built this way, and it is why the order of multiplication is the detail that most often goes wrong.
The three building blocks
Writing points as column vectors and reading the matrix columns as the images of the standard basis vectors e1 = (1, 0) and e2 = (0, 1):
Transformation | Matrix (row by row) | Where e1 and e2 go |
|---|---|---|
Rotation by angle θ counterclockwise about the origin | [[cos θ, −sin θ], [sin θ, cos θ]] | e1 to (cos θ, sin θ); e2 to (−sin θ, cos θ) |
Scaling by sx horizontally and sy vertically | [[sx, 0], [0, sy]] | e1 to (sx, 0); e2 to (0, sy) |
Reflection across the x-axis | [[1, 0], [0, −1]] | e1 fixed; e2 to (0, −1) |
Reflection across the y-axis | [[−1, 0], [0, 1]] | e1 to (−1, 0); e2 fixed |
Reflection across the line y = x | [[0, 1], [1, 0]] | e1 and e2 swap |
The basis-image reading is the fastest way to recover any of these from memory. If you want the matrix that reflects across y = x, ask where (1, 0) goes: to (0, 1). That is the first column. Where does (0, 1) go? To (1, 0). That is the second column. The matrix assembles itself.
Composition: the matrix on the left acts last
If a vertex v is first transformed by A and the result is then transformed by B, the final image is B(Av) = (BA)v. The single matrix is BA, with the later operation written on the left. Reading a product right to left tells you the order of operations in time.
Worked example. Rotate by 90° counterclockwise, then stretch horizontally by a factor of 3 leaving the vertical scale unchanged. Here
R = [[0, −1], [1, 0]] and S = [[3, 0], [0, 1]],
and since the scaling happens second, the combined matrix is
M = SR = [[3, 0], [0, 1]][[0, −1], [1, 0]] = [[0, −3], [1, 0]].
Check it on the vertex (2, 5). Rotating first sends (2, 5) to (0(2) − 1(5), 1(2) + 0(5)) = (−5, 2). Scaling that result gives (3(−5), 1(2)) = (−15, 2). Applying M directly: (0(2) − 3(5), 1(2) + 0(5)) = (−15, 2). The two routes agree.
Now reverse the order. Stretching first and rotating second gives
RS = [[0, −1], [1, 0]][[3, 0], [0, 1]] = [[0, −1], [3, 0]],
which sends (2, 5) to (−5, 6), a genuinely different point. Matrix multiplication is not commutative, and in graphics that is not an algebraic curiosity: stretching a rotated sprite and rotating a stretched sprite produce visibly different images.
The determinant reads off area and orientation
For a linear map of the plane, |det M| is the factor by which every area is multiplied, and the sign of det M records orientation. A rotation has determinant 1 (area and orientation preserved); a scaling by (sx, sy) has determinant sxsy.
Every reflection across a line through the origin has determinant −1. For the composite SR above, det = (0)(0) − (−3)(1) = 3, matching det S × det R = 3 × 1. Determinants multiply along a composition, which makes them a cheap independent check on a chain of transformations.
Habits that prevent the usual errors
- Decide which operation happens last, and write that matrix leftmost.
- Verify a composite by pushing one concrete vertex through the chain step by step and comparing.
- Check the determinant against the expected area and orientation change.
- Remember that all of these matrices fix the origin. Translation is not a 2 × 2 linear map, which is exactly why graphics systems move to homogeneous coordinates, a separate topic.
Mark Yourself Question
- Grab a piece of paper and try this problem yourself.
- When you're done, check the "I have answered this question" box below.
- View the solution and report whether you got it right or wrong.
A vertex of a polygon sits at (6, −2). The renderer rotates the polygon 30° counterclockwise about the origin. Give the exact coordinates of the image of this vertex, then a decimal value to three places.
A sprite is first scaled by a factor of 2 in the x-direction and 4 in the y-direction, and the result is then rotated 90° clockwise about the origin. Vertices are column vectors and matrices act on the left. Which single matrix performs both steps?