In computer graphics, we want to scale, rotate, and slide every point of a shape using a single matrix multiplication.
1
Sliding a 2D Plane by Shearing 3D Space
We want a matrix that slides any 2D point (x,y) by 5 units right and 2 units up to (x+5,y+2). A 2×2 matrix can stretch or rotate the plane around the origin (0,0), but it can never slide the plane because every matrix sends (0,0) to (0,0). To slide the 2D plane with a matrix, we lift it into 3D space to height 1.
Sliding a 2D Plane by Shearing 3D Space
[????][xy]=[x+5y+2]
Text solution
1. Lift the 2D point to height 1Put a 1 in the third slot so the point sits on a flat plane above the fixed 3D origin (0,0,0).
(x,y)→xy1
2. Tilt the third basis arrow to (5,2,1)Keep the first two columns unchanged and put the slide into the third column, so the 1 at the bottom of the point adds that third column once to x and y.
On the plane at height 1, the point (x,y) lands at (x+5,y+2).
Try tilting the third basis arrow below to see how shearing 3D space slides the 2D triangle at height 1 without stretching or rotating it.
Tilting the third basis arrow across the height-1 plane shears 3D space around the fixed origin and slides every 2D point on the plane by the matrix’s third column.
2
Combining Rotation and Translation
Now that a slide is a 3×3 matrix, we want to combine a 90∘ counter-clockwise rotation around (0,0) and a slide by (5,2) into a single 3×3 matrix, and find where the corner (3,2) lands under both orders of the two moves.
Combining Rotation and Translation
TRTR=100010521=turn 90∘=?RT=?
Rotate then slide, TR
Slide then rotate, RT
Text solution
When multiplying matrices in a chain, the move that happens first goes on the right because it multiplies the point vector first.
1. Rotate 90∘ first, then slide by (5,2)The first two columns of the rotation matrix have 0 at the bottom, so they ignore the slide column, while the third column has 1 at the bottom and takes 1 step of 521.
3. Flip the order: slide by (5,2) first, then rotate 90∘Now the rotation matrix on the left multiplies the third column 521 of the slide matrix, rotating the (5,2) slide itself to (−2,5).
4. Apply RT to (3,2) at height 1The rotated first two columns rotate (3,2) to (−2,3), and the third column adds the rotated slide (−2,5) to land at (−4,8).
Rotating then sliding lands the corner at (3,5), whereas sliding then rotating rotates the (5,2) slide around the origin too and lands the corner at (−4,8).
3
Rotating and Scaling Around Any Point
Standard rotation and scaling matrices only spin or stretch around the origin (0,0), so a rotation swings a distant shape around the origin in a wide arc. We want a single 3×3 matrix that rotates a shape 90∘ counter-clockwise in place around its own center at (5,2).
Rotating and Scaling Around Any Point
Text solution
1. Slide (5,2) to (0,0), rotate, and slide backWrite the three matrices from right to left so the first move is on the right.
3. Slide back1000105212. Rotate010−1000011. Slide to (0,0)100010−5−21
2. Multiply the left two matricesSince the rotation happens before the slide back by (5,2), the rotation sits in the top-left and 521 sits in the third column.
010−100521100010−5−21
3. Multiply by the right matrixThe first two columns of the right matrix are 100 and 010, so they pick out the first two columns of the left matrix unchanged, while the third column takes −5 steps of column 1, −2 steps of column 2, and 1 step of column 3.
−5010−2−100+1521=2+5−5+21=7−31
010−100521100010−5−21=010−1007−31
You can quickly check your matrix by plugging in the center (5,2) itself: 010−1007−31521=521, confirming that (5,2) stays fixed while every other point spins 90∘ around it.
Move the center around below and watch the three moves play out: notice that the center is the only point that lands back on itself, and moving it changes only the third column of the combined matrix while the 2×2 rotation block stays the same.
Wherever you place the pivot, the three-step trip keeps only that pivot in place and changes only the third column of the 3×3 matrix, while the 2×2 rotation block stays the same.
4
Homogeneous Coordinates: Directions and Projection
Writing a 2D vector with a third coordinate w as xyw is called homogeneous coordinates. Allowing w to be something other than 1 lets a single matrix handle both positions and directions, and projects points from any nonzero height w onto our 2D screen at w=1.
Homogeneous Coordinates: Directions and Projection
Text solution
1. Set w=0 to transform a direction without sliding itA direction arrow like xy0 has 0 at the bottom, so it takes 0 steps of the third column.
2. Divide by w to project a point with w=0 onto the w=1 screenA point like (6,4,2) at height w=2 lies on a straight line from the eye at (0,0,0) that crosses the w=1 screen halfway back.
642→26241=321
Every nonzero multiple 3w2ww lies on that same line through (0,0,0) and lands on the same 2D point (3,2) on the w=1 screen, while a direction with w=0 is parallel to the w=1 screen, so it never meets the screen and only rotates or scales.
Slide the point along the line through (0,0,0) below, even to negative w behind the origin, to see that every point on the line meets the w=1 screen at the same spot (wx,wy,1), while tilting the line moves that spot.
Every point on the same line through the origin divides down to the exact same point on the screen.
5
4×4 Matrices and 3D Perspective
To draw a 3D world with left-right coordinate x, up-down coordinate y, and depth z in front of the camera, we add a fourth coordinate to write 3D points as xyz1. We want a 4×4 matrix that creates 3D perspective on a 2D screen by dividing x and y by the depth z.
4×4 Matrices and 3D Perspective
z
screen
xyz1→screen (?,?)
Text solution
1. Put 1 at the bottom of column 3 to copy depth z into the w slotMultiplying by xyz1 keeps x and y in the first two slots and places z into the fourth slot w.
2. Divide the vector by w to return to w=1Because the graphics pipeline automatically divides every slot by w at the end, dividing by w=z divides x and y by the depth z.
xyzz→zxzy11
The 3D point (x,y,z) lands on the 2D screen at (zx,zy), so objects further away with a larger depth z look smaller and move closer to the center of the screen.
Move the 3D tree deeper in z below to see how copying z into w and dividing shrinks (zx,zy) toward the center of the z=1 screen.
Copying an object's depth into the bottom slot makes dividing by that slot shrink farther objects toward the center of the screen.
Key concepts
Every homogeneous vector puts an extra coordinate w at the bottom to control how the last column of a matrix acts on it and how it projects onto the screen:
Positions (w=1) vs. directions (w=0)
Put w=1 on a point so it takes 1 step of the slide column, and put w=0 on a direction arrow so it takes 0 steps of the slide column while still rotating and scaling:
Chaining moves (right to left) and choosing a center
Always place the first move on the right. When a shape rotates or scales around (0,0) first and slides second, you do not need a three-step chain or extra multiplication: the 2×2 matrix sits in the top-left and the slide sits in the third column:
100010521010−100001=010−100521
If the slide happens before a rotation around (0,0), multiply the matrices out because the rotation transforms the third column's slide too. And if a shape rotates or scales in place around a center (a,b) other than (0,0), put the transformation between sliding (a,b) to (0,0) on the right and sliding back to (a,b) on the left:
Dividing by w for screen projection and 3D perspective
If the output vector already has w=1, read off the coordinates directly with no division. Whenever a vector has any other nonzero w, divide every slot by w to project along the line through the origin onto the w=1 screen, such as 642→321. In 3D, a 4×4 perspective matrix puts a 1 at the bottom of column 3 so that depth z copies into w, turning xyz1 into xyzz→zxzy11.
6
Practice
1
Write the single 3×3 matrix that first doubles the size of a 2D shape and then slides it 4 units left and 3 units up, and find where the corner (2,−1) lands.
Which matrix multiplies the point vector 2−11 first: the scaling matrix on the right or the slide matrix on the left?
Because doubling happens first, the scaling matrix goes on the right and the translation matrix goes on the left:
100010−431200020001=200020−431
(Watch out: writing the matrices from left to right as 200020001100010−431=200020−861 slides the shape first and doubles the slide too, giving the wrong landing spot (−4,4).)
A triangle is first slid 3 units right and 4 units down, and then rotated 90∘ counter-clockwise around the origin (0,0). Find the single 3×3 matrix for this two-step move, and explain why its third column is not 3−41.
Since the slide happens first, place the slide matrix on the right and check what the 90∘ rotation matrix on the left does to its third column 3−41.
Because the slide happens first, it goes on the right and the 90∘ counter-clockwise rotation goes on the left:
010−1000011000103−41=010−100431
(Watch out: putting the rotation into the top-left and the slide into the third column gives 010−1003−41, which is the matrix for rotating first and sliding second.)
The third column is 431 because the 90∘ rotation happens second and rotates the (3,−4) slide itself to (4,3).
3
A 2D scene is transformed by the matrix M=010−1006−21. Use M to transform both a triangle corner at (1,4) and a sunlight direction arrow pointing along (1,4).
What bottom coordinate w distinguishes a position that slides from a direction arrow that ignores slides?
(Watch out: putting w=1 on the sunlight arrow adds the 6−21 slide column to the direction and gives the wrong vector (2,−1).)
The corner moves to (2,−1), and the sunlight direction rotates to (−4,1).
4
Which of the homogeneous vectors 8−42,−126−3,4−20, and 20−105 land on the same 2D point on the w=1 screen, what is that point, and what does 4−20 represent instead?
How do you project a vector xyw onto the screen at height w=1, and what happens when w=0?
Divide each vector with a nonzero w by its bottom coordinate w:
(Watch out: don't leave out −126−3 because of its signs, since dividing by w=−3 flips the signs to 4−21, and don't include 4−20 as a point just because its first two entries are 4 and −2.)
The vectors 8−42,−126−3, and 20−105 all lie on the same line through the origin and represent the 2D point (4,−2), while 4−20 has w=0 and represents the 2D direction (4,−2).
5
Find the single 3×3 matrix that doubles the size of a 2D shape in place around its center at (3,−1), and use it to find where the corner (5,2) lands.
What three steps keep (3,−1) fixed at the origin during the scaling, and which slide goes on the right?
First slide (3,−1) to (0,0) by (−3,1) on the right, then double the size in the middle, and finally slide back by (3,−1) on the left:
(Watch out: swapping the two slides by putting (3,−1) on the right and (−3,1) on the left gives 2000203−11, which sends (5,2) to the wrong point (13,3).)
A 3D point at (6,−3,2) is first slid by (2,5,2) in 3D space and then projected onto the 2D screen by the 4×4 perspective matrix. Multiply the two 4×4 matrices into one matrix, apply it to 6−321, and divide by w to find where the point lands on the 2D screen.
Watch out: stopping before the division by w=4 gives (8,2), and dividing by the original depth z=2 instead of the new depth w=4 gives (4,1).
Where is the 1 located in the bottom row of the 4×4 perspective matrix so that it copies the new depth z into the w slot?
Multiply the perspective matrix on the left by the 3D translation matrix on the right: