Matrices in Computer Graphics
Sliding an object isn't a linear transformation, so plain matrices can't do it. Tack a 1 onto every point and suddenly they can, which means any chain of rotations, scalings and moves collapses into one matrix you apply to every vertex.
What the symbols mean
- Shift in x
Translations aren't linear in ordinary coordinates, but they are in homogeneous ones.
Explanation
Homogeneous coordinates are simply ordinary coordinates with an extra 1 tacked on the end, so the point becomes . The name comes from projective geometry, where scaling all the coordinates together, like , still describes the same point. It's good for one very practical reason: it lets a single matrix slide things around, which ordinary matrices can't do. The translation formula looks like a big block of numbers, but it's mostly the identity: the s and s leave and alone, and and (the shifts) sit in the last column, where that extra picks them up and adds them on. That's the whole trick.
The problem. Rotation and scaling are linear, so they're matrices. Moving an object isn't: a linear transformation always sends to , and a translation moves the origin. Graphics needs all three constantly.
The fix. Represent as . Now a matrix can rotate, scale and translate. In 3D, points become and matrices are .
Composition. This is matrix multiplication from the start of the unit, put to work. To scale, then rotate, then move, multiply (rightmost first) into one matrix and apply it to every vertex. A game might do that for millions of vertices every frame, so combining first saves a lot of work.
A common mistake. It's tempting to think the order of the moves doesn't matter, since you end up doing all of them anyway. It does: rotating then translating differs from translating then rotating, because rotation always spins around the origin, and translating first changes where the object sits relative to it.
Perspective. The last row can also do perspective division, and that's how a 3D scene gets projected onto your screen.
See it
Worked examples
Translate the point by with a homogeneous matrix.
- 1
Write the point as and put the shift in the last column. The extra picks up the shift: .
Practice
Type your answer and check it. Solve them all to complete the lesson.
Translate by .
Give the homogeneous matrix that translates by , row by row.
Scale by 2, then translate by . Where does it end up?
Does rotating then translating give the same result as translating then rotating?
Give the homogeneous coordinates of .
A game sprite at is rotated counterclockwise about the point . Where does it end up?
The hardest one here. Get it, and you've got this lesson.
Give the homogeneous matrix for "rotate counterclockwise about ", row by row.
Where it's used
Every 3D game and CAD program multiplies 4×4 homogeneous matrices for every vertex, every frame; the camera projection lab uses exactly this pipeline.