Linear AlgebraApplications5 of 6
Applications · 5

Computer Graphics and Homogeneous Coordinates

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)\point{(x, y)} by 5\slide{5} units right and 2\slide{2} units up to (x+5,y+2)(\point{x} + \slide{5}, \point{y} + \slide{2}). A 2×22 \times 2 matrix can stretch or rotate the plane around the origin (0,0)(0, 0), but it can never slide the plane because every matrix sends (0,0)(0, 0) to (0,0)(0, 0). To slide the 2D plane with a matrix, we lift it into 3D space to height 1\slide{1}.

Sliding a 2D Plane by Shearing 3D Space
(3,2)\htmlClass{lc-blue}{(3, 2)}
5\htmlClass{lc-violet}{5}
2\htmlClass{lc-violet}{2}
[????][xy]=[x+5y+2]\displaystyle \begin{bmatrix} \htmlClass{lc-mute}{?} & \htmlClass{lc-mute}{?} \\ \htmlClass{lc-mute}{?} & \htmlClass{lc-mute}{?} \end{bmatrix}\begin{bmatrix} \point{x} \\ \point{y} \end{bmatrix} = \begin{bmatrix} \point{x} + \slide{5} \\ \point{y} + \slide{2} \end{bmatrix}
Text solution
1. Lift the 2D point to height 1\slide{1}Put a 1\slide{1} in the third slot so the point sits on a flat plane above the fixed 3D origin (0,0,0)(0, 0, 0).
(x,y)→[xy1]\displaystyle \point{(x, y)} \to \begin{bmatrix} \point{x} \\ \point{y} \\ \slide{1} \end{bmatrix}
2. Tilt the third basis arrow to (5,2,1)\slide{(5, 2, 1)}Keep the first two columns unchanged and put the slide into the third column, so the 1\slide{1} at the bottom of the point adds that third column once to x\point{x} and y\point{y}.
[105012001][xy1]=x[100]+y[010]+1[521]=[x+5y+21]\displaystyle \begin{aligned} & \begin{bmatrix} \first{1} & \second{0} & \slide{5} \\ \first{0} & \second{1} & \slide{2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \point{x} \\ \point{y} \\ \slide{1} \end{bmatrix} \\ &= \first{x}\begin{bmatrix} \first{1} \\ \first{0} \\ \first{0} \end{bmatrix} + \second{y}\begin{bmatrix} \second{0} \\ \second{1} \\ \second{0} \end{bmatrix} + \slide{1}\begin{bmatrix} \slide{5} \\ \slide{2} \\ \slide{1} \end{bmatrix} \\ &= \begin{bmatrix} \point{x} + \slide{5} \\ \point{y} + \slide{2} \\ \slide{1} \end{bmatrix} \end{aligned}

On the plane at height 1\slide{1}, the point (x,y)\point{(x, y)} lands at (x+5,y+2)(\point{x} + \slide{5}, \point{y} + \slide{2}).

Try tilting the third basis arrow below to see how shearing 3D space slides the 2D triangle at height 1\slide{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×33 \times 3 matrix, we want to combine a 90∘90^\circ counter-clockwise rotation around (0,0)(0, 0) and a slide by (5,2)\slide{(5, 2)} into a single 3×33 \times 3 matrix, and find where the corner (3,2)\point{(3, 2)} lands under both orders of the two moves.

Combining Rotation and Translation
T=[105012001]R=turn 90∘TR=  ?RT=  ?\displaystyle \begin{aligned} T &= \begin{bmatrix} \htmlClass{lc-green}{1} & \htmlClass{lc-pink}{0} & \htmlClass{lc-violet}{5} \\ \htmlClass{lc-green}{0} & \htmlClass{lc-pink}{1} & \htmlClass{lc-violet}{2} \\ \htmlClass{lc-green}{0} & \htmlClass{lc-pink}{0} & \htmlClass{lc-violet}{1} \end{bmatrix} \\[22pt] R &= \text{turn } 90^\circ \\[4pt] TR &= \;? \qquad RT = \;? \end{aligned}
Rotate then slide, TRTR
(0,0)(0, 0)
(3,2)\htmlClass{lc-blue}{(3, 2)}
(−2,3)\htmlClass{lc-blue}{(-2, 3)}
(5,2)\htmlClass{lc-violet}{(5, 2)}
(3,5)\htmlClass{lc-blue}{(3, 5)}
Slide then rotate, RTRT
(0,0)(0, 0)
(5,2)\htmlClass{lc-violet}{(5, 2)}
(8,4)\htmlClass{lc-blue}{(8, 4)}
(−2,5)\htmlClass{lc-violet}{(-2, 5)}
(−4,8)\htmlClass{lc-blue}{(-4, 8)}
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∘90^\circ first, then slide by (5,2)\slide{(5, 2)}The first two columns of the rotation matrix have 00 at the bottom, so they ignore the slide column, while the third column has 1\slide{1} at the bottom and takes 1\slide{1} step of [521]\begin{bmatrix} \slide{5} \\ \slide{2} \\ \slide{1} \end{bmatrix}.
[105012001]⏟2. Slide T[0−10100001]⏟1. Rotate R=[0−15102001]\displaystyle \underbrace{\begin{bmatrix} \first{1} & \second{0} & \slide{5} \\ \first{0} & \second{1} & \slide{2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}}_{\text{2. Slide } T}\underbrace{\begin{bmatrix} \first{0} & \second{-1} & \slide{0} \\ \first{1} & \second{0} & \slide{0} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}}_{\text{1. Rotate } R} = \begin{bmatrix} \first{0} & \second{-1} & \slide{5} \\ \first{1} & \second{0} & \slide{2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}
2. Apply TRTR to (3,2)\point{(3, 2)} at height 1\slide{1}The top-left 2×22 \times 2 block rotates (3,2)\point{(3, 2)} to (−2,3)\point{(-2, 3)}, and the third column adds (5,2)\slide{(5, 2)}.
[0−15102001][321]=3[010]+2[−100]+1[521]=[351]\displaystyle \begin{aligned} & \begin{bmatrix} \first{0} & \second{-1} & \slide{5} \\ \first{1} & \second{0} & \slide{2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \point{3} \\ \point{2} \\ \slide{1} \end{bmatrix} \\ &= \first{3}\begin{bmatrix} \first{0} \\ \first{1} \\ \first{0} \end{bmatrix} + \second{2}\begin{bmatrix} \second{-1} \\ \second{0} \\ \second{0} \end{bmatrix} + \slide{1}\begin{bmatrix} \slide{5} \\ \slide{2} \\ \slide{1} \end{bmatrix} \\ &= \begin{bmatrix} \point{3} \\ \point{5} \\ \slide{1} \end{bmatrix} \end{aligned}
3. Flip the order: slide by (5,2)\slide{(5, 2)} first, then rotate 90∘90^\circNow the rotation matrix on the left multiplies the third column [521]\begin{bmatrix} \slide{5} \\ \slide{2} \\ \slide{1} \end{bmatrix} of the slide matrix, rotating the (5,2)\slide{(5, 2)} slide itself to (−2,5)\slide{(-2, 5)}.
[0−10100001]⏟2. Rotate R[105012001]⏟1. Slide T=[0−1−2105001]\displaystyle \underbrace{\begin{bmatrix} \first{0} & \second{-1} & \slide{0} \\ \first{1} & \second{0} & \slide{0} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}}_{\text{2. Rotate } R}\underbrace{\begin{bmatrix} \first{1} & \second{0} & \slide{5} \\ \first{0} & \second{1} & \slide{2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}}_{\text{1. Slide } T} = \begin{bmatrix} \first{0} & \second{-1} & \slide{-2} \\ \first{1} & \second{0} & \slide{5} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}
4. Apply RTRT to (3,2)\point{(3, 2)} at height 1\slide{1}The rotated first two columns rotate (3,2)\point{(3, 2)} to (−2,3)\point{(-2, 3)}, and the third column adds the rotated slide (−2,5)\slide{(-2, 5)} to land at (−4,8)\point{(-4, 8)}.
[0−1−2105001][321]=3[010]+2[−100]+1[−251]=[−481]\displaystyle \begin{aligned} & \begin{bmatrix} \first{0} & \second{-1} & \slide{-2} \\ \first{1} & \second{0} & \slide{5} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \point{3} \\ \point{2} \\ \slide{1} \end{bmatrix} \\ &= \first{3}\begin{bmatrix} \first{0} \\ \first{1} \\ \first{0} \end{bmatrix} + \second{2}\begin{bmatrix} \second{-1} \\ \second{0} \\ \second{0} \end{bmatrix} + \slide{1}\begin{bmatrix} \slide{-2} \\ \slide{5} \\ \slide{1} \end{bmatrix} \\ &= \begin{bmatrix} \point{-4} \\ \point{8} \\ \slide{1} \end{bmatrix} \end{aligned}

Rotating then sliding lands the corner at (3,5)\point{(3, 5)}, whereas sliding then rotating rotates the (5,2)\slide{(5, 2)} slide around the origin too and lands the corner at (−4,8)\point{(-4, 8)}.

3

Rotating and Scaling Around Any Point

Standard rotation and scaling matrices only spin or stretch around the origin (0,0)(0, 0), so a rotation swings a distant shape around the origin in a wide arc. We want a single 3×33 \times 3 matrix that rotates a shape 90∘90^\circ counter-clockwise in place around its own center at (5,2)(5, 2).

Rotating and Scaling Around Any Point
(5,2)(5, 2)
Text solution
1. Slide (5,2)(5, 2) to (0,0)(0, 0), rotate, and slide backWrite the three matrices from right to left so the first move is on the right.
[105012001]⏟3. Slide back[0−10100001]⏟2. Rotate[10−501−2001]⏟1. Slide to (0,0)\displaystyle \begin{aligned} & \underbrace{\begin{bmatrix} \first{1} & \second{0} & \slide{5} \\ \first{0} & \second{1} & \slide{2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}}_{\text{3. Slide back}}\underbrace{\begin{bmatrix} \first{0} & \second{-1} & \slide{0} \\ \first{1} & \second{0} & \slide{0} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}}_{\text{2. Rotate}} \\ &\qquad \underbrace{\begin{bmatrix} \first{1} & \second{0} & \slide{-5} \\ \first{0} & \second{1} & \slide{-2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}}_{\text{1. Slide to } (0, 0)} \end{aligned}
2. Multiply the left two matricesSince the rotation happens before the slide back by (5,2)\slide{(5, 2)}, the rotation sits in the top-left and [521]\begin{bmatrix} \slide{5} \\ \slide{2} \\ \slide{1} \end{bmatrix} sits in the third column.
[0−15102001][10−501−2001]\displaystyle \begin{bmatrix} \first{0} & \second{-1} & \slide{5} \\ \first{1} & \second{0} & \slide{2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \first{1} & \second{0} & \slide{-5} \\ \first{0} & \second{1} & \slide{-2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}
3. Multiply by the right matrixThe first two columns of the right matrix are [100]\begin{bmatrix} \first{1} \\ \first{0} \\ \first{0} \end{bmatrix} and [010]\begin{bmatrix} \second{0} \\ \second{1} \\ \second{0} \end{bmatrix}, so they pick out the first two columns of the left matrix unchanged, while the third column takes −5\first{-5} steps of column 1, −2\second{-2} steps of column 2, and 1\slide{1} step of column 3.
−5[010]−2[−100]+1[521]=[2+5−5+21]=[7−31]\displaystyle \begin{aligned} & \first{-5}\begin{bmatrix} \first{0} \\ \first{1} \\ \first{0} \end{bmatrix} - \second{2}\begin{bmatrix} \second{-1} \\ \second{0} \\ \second{0} \end{bmatrix} + \slide{1}\begin{bmatrix} \slide{5} \\ \slide{2} \\ \slide{1} \end{bmatrix} \\ &= \begin{bmatrix} \second{2} + \slide{5} \\ \first{-5} + \slide{2} \\ \slide{1} \end{bmatrix} \\ &= \begin{bmatrix} \slide{7} \\ \slide{-3} \\ \slide{1} \end{bmatrix} \end{aligned}
[0−15102001][10−501−2001]=[0−1710−3001]\displaystyle \begin{bmatrix} \first{0} & \second{-1} & \slide{5} \\ \first{1} & \second{0} & \slide{2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \first{1} & \second{0} & \slide{-5} \\ \first{0} & \second{1} & \slide{-2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix} = \begin{bmatrix} \first{0} & \second{-1} & \slide{7} \\ \first{1} & \second{0} & \slide{-3} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}

You can quickly check your matrix by plugging in the center (5,2)(5, 2) itself: [0−1710−3001][521]=[521]\begin{bmatrix} \first{0} & \second{-1} & \slide{7} \\ \first{1} & \second{0} & \slide{-3} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} 5 \\ 2 \\ \slide{1} \end{bmatrix} = \begin{bmatrix} 5 \\ 2 \\ \slide{1} \end{bmatrix}, confirming that (5,2)(5, 2) stays fixed while every other point spins 90∘90^\circ 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×22 \times 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\slide{w} as [xyw]\begin{bmatrix} \point{x} \\ \point{y} \\ \slide{w} \end{bmatrix} is called homogeneous coordinates. Allowing w\slide{w} to be something other than 1\slide{1} lets a single matrix handle both positions and directions, and projects points from any nonzero height w\slide{w} onto our 2D screen at w=1\slide{w} = \slide{1}.

Homogeneous Coordinates: Directions and Projection
Text solution
1. Set w=0\slide{w} = \slide{0} to transform a direction without sliding itA direction arrow like [xy0]\begin{bmatrix} \point{x} \\ \point{y} \\ \slide{0} \end{bmatrix} has 0\slide{0} at the bottom, so it takes 0\slide{0} steps of the third column.
[0−15102001][xy0]=x[010]+y[−100]+0[521]=[−yx0]\displaystyle \begin{aligned} & \begin{bmatrix} \first{0} & \second{-1} & \slide{5} \\ \first{1} & \second{0} & \slide{2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \point{x} \\ \point{y} \\ \slide{0} \end{bmatrix} \\ &= \first{x}\begin{bmatrix} \first{0} \\ \first{1} \\ \first{0} \end{bmatrix} + \second{y}\begin{bmatrix} \second{-1} \\ \second{0} \\ \second{0} \end{bmatrix} + \slide{0}\begin{bmatrix} \slide{5} \\ \slide{2} \\ \slide{1} \end{bmatrix} \\ &= \begin{bmatrix} \point{-y} \\ \point{x} \\ \slide{0} \end{bmatrix} \end{aligned}
2. Divide by w\slide{w} to project a point with w≠0\slide{w} \neq 0 onto the w=1\slide{w} = \slide{1} screenA point like (6,4,2)(\point{6}, \point{4}, \slide{2}) at height w=2\slide{w} = \slide{2} lies on a straight line from the eye at (0,0,0)(0, 0, 0) that crosses the w=1\slide{w} = \slide{1} screen halfway back.
[642]→[62421]=[321]\displaystyle \begin{bmatrix} \point{6} \\ \point{4} \\ \slide{2} \end{bmatrix} \to \begin{bmatrix} \tfrac{\point{6}}{\slide{2}} \\ \tfrac{\point{4}}{\slide{2}} \\ \slide{1} \end{bmatrix} = \begin{bmatrix} \point{3} \\ \point{2} \\ \slide{1} \end{bmatrix}

Every nonzero multiple [3w2ww]\begin{bmatrix} \point{3}\slide{w} \\ \point{2}\slide{w} \\ \slide{w} \end{bmatrix} lies on that same line through (0,0,0)(0, 0, 0) and lands on the same 2D point (3,2)\point{(3, 2)} on the w=1\slide{w} = \slide{1} screen, while a direction with w=0\slide{w} = \slide{0} is parallel to the w=1\slide{w} = \slide{1} screen, so it never meets the screen and only rotates or scales.

Slide the point along the line through (0,0,0)(0, 0, 0) below, even to negative w\slide{w} behind the origin, to see that every point on the line meets the w=1\slide{w} = \slide{1} screen at the same spot (xw,yw,1)(\tfrac{\point{x}}{\slide{w}}, \tfrac{\point{y}}{\slide{w}}, \slide{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 xx, up-down coordinate yy, and depth z\depth{z} in front of the camera, we add a fourth coordinate to write 3D points as [xyz1]\begin{bmatrix} x \\ y \\ \depth{z} \\ \slide{1} \end{bmatrix}. We want a 4×44 \times 4 matrix that creates 3D perspective on a 2D screen by dividing xx and yy by the depth z\depth{z}.

4×4 Matrices and 3D Perspective
[xyz1]  →  screen (  ?  ,  ?  )\displaystyle \begin{bmatrix} x \\ y \\ \depth{z} \\ \slide{1} \end{bmatrix} \;\to\; \text{screen } (\;?\;,\;?\;)
Text solution
1. Put 1\depth{1} at the bottom of column 3 to copy depth z\depth{z} into the w\slide{w} slotMultiplying by [xyz1]\begin{bmatrix} x \\ y \\ \depth{z} \\ \slide{1} \end{bmatrix} keeps xx and yy in the first two slots and places z\depth{z} into the fourth slot w\slide{w}.
[1000010000100010][xyz1]=[x000]+[0y00]+[00zz]+[0000]=[xyzz]\displaystyle \begin{aligned} & \begin{bmatrix} \first{1} & \second{0} & \depth{0} & \slide{0} \\ \first{0} & \second{1} & \depth{0} & \slide{0} \\ \first{0} & \second{0} & \depth{1} & \slide{0} \\ \first{0} & \second{0} & \depth{1} & \slide{0} \end{bmatrix}\begin{bmatrix} x \\ y \\ \depth{z} \\ \slide{1} \end{bmatrix} \\ &= \begin{bmatrix} \first{x} \\ 0 \\ 0 \\ 0 \end{bmatrix} + \begin{bmatrix} 0 \\ \second{y} \\ 0 \\ 0 \end{bmatrix} + \begin{bmatrix} 0 \\ 0 \\ \depth{z} \\ \depth{z} \end{bmatrix} + \begin{bmatrix} 0 \\ 0 \\ 0 \\ 0 \end{bmatrix} \\ &= \begin{bmatrix} x \\ y \\ \depth{z} \\ \depth{z} \end{bmatrix} \end{aligned}
2. Divide the vector by w\slide{w} to return to w=1\slide{w} = \slide{1}Because the graphics pipeline automatically divides every slot by w\slide{w} at the end, dividing by w=z\slide{w} = \depth{z} divides xx and yy by the depth z\depth{z}.
[xyzz]→[xzyz11]\displaystyle \begin{bmatrix} x \\ y \\ \depth{z} \\ \depth{z} \end{bmatrix} \to \begin{bmatrix} \tfrac{x}{\depth{z}} \\ \tfrac{y}{\depth{z}} \\ 1 \\ \slide{1} \end{bmatrix}

The 3D point (x,y,z)(x, y, \depth{z}) lands on the 2D screen at (xz,yz)(\tfrac{x}{\depth{z}}, \tfrac{y}{\depth{z}}), so objects further away with a larger depth z\depth{z} look smaller and move closer to the center of the screen.

Move the 3D tree deeper in z\depth{z} below to see how copying z\depth{z} into w\slide{w} and dividing shrinks (xz,yz)(\tfrac{x}{\depth{z}}, \tfrac{y}{\depth{z}}) toward the center of the z=1\depth{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\slide{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\slide{w} = \slide{1}) vs. directions (w=0\slide{w} = \slide{0})

Put w=1\slide{w} = \slide{1} on a point so it takes 1\slide{1} step of the slide column, and put w=0\slide{w} = \slide{0} on a direction arrow so it takes 0\slide{0} steps of the slide column while still rotating and scaling:

[0−15102001][321]=[351],[0−15102001][1−10]=[110]\displaystyle \begin{aligned} \begin{bmatrix} \first{0} & \second{-1} & \slide{5} \\ \first{1} & \second{0} & \slide{2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \point{3} \\ \point{2} \\ \slide{1} \end{bmatrix} &= \begin{bmatrix} \point{3} \\ \point{5} \\ \slide{1} \end{bmatrix}, \\ \begin{bmatrix} \first{0} & \second{-1} & \slide{5} \\ \first{1} & \second{0} & \slide{2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \point{1} \\ \point{-1} \\ \slide{0} \end{bmatrix} &= \begin{bmatrix} \point{1} \\ \point{1} \\ \slide{0} \end{bmatrix} \end{aligned}

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)(0, 0) first and slides second, you do not need a three-step chain or extra multiplication: the 2×22 \times 2 matrix sits in the top-left and the slide sits in the third column:

[105012001][0−10100001]=[0−15102001]\displaystyle \begin{bmatrix} \first{1} & \second{0} & \slide{5} \\ \first{0} & \second{1} & \slide{2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \first{0} & \second{-1} & \slide{0} \\ \first{1} & \second{0} & \slide{0} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix} = \begin{bmatrix} \first{0} & \second{-1} & \slide{5} \\ \first{1} & \second{0} & \slide{2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}
If the slide happens before a rotation around (0,0)(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)(a, b) other than (0,0)(0, 0), put the transformation between sliding (a,b)(a, b) to (0,0)(0, 0) on the right and sliding back to (a,b)(a, b) on the left:
[105012001][0−10100001][10−501−2001]=[0−1710−3001]\displaystyle \begin{aligned} & \begin{bmatrix} \first{1} & \second{0} & \slide{5} \\ \first{0} & \second{1} & \slide{2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \first{0} & \second{-1} & \slide{0} \\ \first{1} & \second{0} & \slide{0} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix} \\ &\qquad \begin{bmatrix} \first{1} & \second{0} & \slide{-5} \\ \first{0} & \second{1} & \slide{-2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix} \\ &\quad = \begin{bmatrix} \first{0} & \second{-1} & \slide{7} \\ \first{1} & \second{0} & \slide{-3} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix} \end{aligned}

Dividing by w\slide{w} for screen projection and 3D perspective

If the output vector already has w=1\slide{w} = \slide{1}, read off the coordinates directly with no division. Whenever a vector has any other nonzero w\slide{w}, divide every slot by w\slide{w} to project along the line through the origin onto the w=1\slide{w} = \slide{1} screen, such as [642]→[321]\begin{bmatrix} \point{6} \\ \point{4} \\ \slide{2} \end{bmatrix} \to \begin{bmatrix} \point{3} \\ \point{2} \\ \slide{1} \end{bmatrix}. In 3D, a 4×44 \times 4 perspective matrix puts a 1\depth{1} at the bottom of column 3 so that depth z\depth{z} copies into w\slide{w}, turning [xyz1]\begin{bmatrix} x \\ y \\ \depth{z} \\ \slide{1} \end{bmatrix} into [xyzz]→[xzyz11]\begin{bmatrix} x \\ y \\ \depth{z} \\ \depth{z} \end{bmatrix} \to \begin{bmatrix} \tfrac{x}{\depth{z}} \\ \tfrac{y}{\depth{z}} \\ 1 \\ \slide{1} \end{bmatrix}.

6

Practice

1

Write the single 3×33 \times 3 matrix that first doubles the size of a 2D shape and then slides it 4\slide{4} units left and 3\slide{3} units up, and find where the corner (2,−1)\point{(2, -1)} lands.

Which matrix multiplies the point vector [2−11]\begin{bmatrix} \point{2} \\ \point{-1} \\ \slide{1} \end{bmatrix} 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:
[10−4013001][200020001]=[20−4023001]\displaystyle \begin{bmatrix} \first{1} & \second{0} & \slide{-4} \\ \first{0} & \second{1} & \slide{3} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \first{2} & \second{0} & \slide{0} \\ \first{0} & \second{2} & \slide{0} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix} = \begin{bmatrix} \first{2} & \second{0} & \slide{-4} \\ \first{0} & \second{2} & \slide{3} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}
(Watch out: writing the matrices from left to right as [200020001][10−4013001]\begin{bmatrix} 2 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 1 \end{bmatrix}\begin{bmatrix} 1 & 0 & -4 \\ 0 & 1 & 3 \\ 0 & 0 & 1 \end{bmatrix} =[20−8026001]{}= \begin{bmatrix} 2 & 0 & -8 \\ 0 & 2 & 6 \\ 0 & 0 & 1 \end{bmatrix} slides the shape first and doubles the slide too, giving the wrong landing spot (−4,4)(-4, 4).)
Multiply the combined matrix by [2−11]\begin{bmatrix} \point{2} \\ \point{-1} \\ \slide{1} \end{bmatrix}:
[20−4023001][2−11]=2[200]−1[020]+1[−431]=[011]\displaystyle \begin{aligned} & \begin{bmatrix} \first{2} & \second{0} & \slide{-4} \\ \first{0} & \second{2} & \slide{3} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \point{2} \\ \point{-1} \\ \slide{1} \end{bmatrix} = \first{2}\begin{bmatrix} \first{2} \\ \first{0} \\ \first{0} \end{bmatrix} \\ &\quad - \second{1}\begin{bmatrix} \second{0} \\ \second{2} \\ \second{0} \end{bmatrix}+ \slide{1}\begin{bmatrix} \slide{-4} \\ \slide{3} \\ \slide{1} \end{bmatrix} = \begin{bmatrix} \point{0} \\ \point{1} \\ \slide{1} \end{bmatrix} \end{aligned}
The corner lands at (0,1)\point{(0, 1)}.
2

A triangle is first slid 3\slide{3} units right and 4\slide{4} units down, and then rotated 90∘90^\circ counter-clockwise around the origin (0,0)(0, 0). Find the single 3×33 \times 3 matrix for this two-step move, and explain why its third column is not [3−41]\begin{bmatrix} \slide{3} \\ \slide{-4} \\ \slide{1} \end{bmatrix}.

Since the slide happens first, place the slide matrix on the right and check what the 90∘90^\circ rotation matrix on the left does to its third column [3−41]\begin{bmatrix} \slide{3} \\ \slide{-4} \\ \slide{1} \end{bmatrix}.

Because the slide happens first, it goes on the right and the 90∘90^\circ counter-clockwise rotation goes on the left:
[0−10100001][10301−4001]=[0−14103001]\displaystyle \begin{bmatrix} \first{0} & \second{-1} & \slide{0} \\ \first{1} & \second{0} & \slide{0} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \first{1} & \second{0} & \slide{3} \\ \first{0} & \second{1} & \slide{-4} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix} = \begin{bmatrix} \first{0} & \second{-1} & \slide{4} \\ \first{1} & \second{0} & \slide{3} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}
(Watch out: putting the rotation into the top-left and the slide into the third column gives [0−1310−4001]\begin{bmatrix} 0 & -1 & 3 \\ 1 & 0 & -4 \\ 0 & 0 & 1 \end{bmatrix}, which is the matrix for rotating first and sliding second.)
The third column is [431]\begin{bmatrix} \slide{4} \\ \slide{3} \\ \slide{1} \end{bmatrix} because the 90∘90^\circ rotation happens second and rotates the (3,−4)\slide{(3, -4)} slide itself to (4,3)\slide{(4, 3)}.
3

A 2D scene is transformed by the matrix M=[0−1610−2001]M = \begin{bmatrix} \first{0} & \second{-1} & \slide{6} \\ \first{1} & \second{0} & \slide{-2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}. Use MM to transform both a triangle corner at (1,4)\point{(1, 4)} and a sunlight direction arrow pointing along (1,4)\point{(1, 4)}.

What bottom coordinate w\slide{w} distinguishes a position that slides from a direction arrow that ignores slides?

The triangle corner is a position (w=1\slide{w} = \slide{1}):
[0−1610−2001][141]=1[010]+4[−100]+1[6−21]=[2−11]\displaystyle \begin{aligned} & \begin{bmatrix} \first{0} & \second{-1} & \slide{6} \\ \first{1} & \second{0} & \slide{-2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \point{1} \\ \point{4} \\ \slide{1} \end{bmatrix} = \first{1}\begin{bmatrix} \first{0} \\ \first{1} \\ \first{0} \end{bmatrix} \\ &\quad + \second{4}\begin{bmatrix} \second{-1} \\ \second{0} \\ \second{0} \end{bmatrix}+ \slide{1}\begin{bmatrix} \slide{6} \\ \slide{-2} \\ \slide{1} \end{bmatrix} \\ &\quad = \begin{bmatrix} \point{2} \\ \point{-1} \\ \slide{1} \end{bmatrix} \end{aligned}
The sunlight arrow is a direction (w=0\slide{w} = \slide{0}):
[0−1610−2001][140]=1[010]+4[−100]+0[6−21]=[−410]\displaystyle \begin{aligned} & \begin{bmatrix} \first{0} & \second{-1} & \slide{6} \\ \first{1} & \second{0} & \slide{-2} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \point{1} \\ \point{4} \\ \slide{0} \end{bmatrix} = \first{1}\begin{bmatrix} \first{0} \\ \first{1} \\ \first{0} \end{bmatrix} \\ &\quad + \second{4}\begin{bmatrix} \second{-1} \\ \second{0} \\ \second{0} \end{bmatrix}+ \slide{0}\begin{bmatrix} \slide{6} \\ \slide{-2} \\ \slide{1} \end{bmatrix} \\ &\quad = \begin{bmatrix} \point{-4} \\ \point{1} \\ \slide{0} \end{bmatrix} \end{aligned}
(Watch out: putting w=1\slide{w} = \slide{1} on the sunlight arrow adds the [6−21]\begin{bmatrix} \slide{6} \\ \slide{-2} \\ \slide{1} \end{bmatrix} slide column to the direction and gives the wrong vector (2,−1)(2, -1).)
The corner moves to (2,−1)\point{(2, -1)}, and the sunlight direction rotates to (−4,1)\point{(-4, 1)}.
4

Which of the homogeneous vectors [8−42]\begin{bmatrix} \point{8} \\ \point{-4} \\ \slide{2} \end{bmatrix}, [−126−3]\begin{bmatrix} \point{-12} \\ \point{6} \\ \slide{-3} \end{bmatrix}, [4−20]\begin{bmatrix} \point{4} \\ \point{-2} \\ \slide{0} \end{bmatrix}, and [20−105]\begin{bmatrix} \point{20} \\ \point{-10} \\ \slide{5} \end{bmatrix} land on the same 2D point on the w=1\slide{w} = \slide{1} screen, what is that point, and what does [4−20]\begin{bmatrix} \point{4} \\ \point{-2} \\ \slide{0} \end{bmatrix} represent instead?

How do you project a vector [xyw]\begin{bmatrix} \point{x} \\ \point{y} \\ \slide{w} \end{bmatrix} onto the screen at height w=1\slide{w} = \slide{1}, and what happens when w=0\slide{w} = \slide{0}?

Divide each vector with a nonzero w\slide{w} by its bottom coordinate w\slide{w}:
[8−42]→[4−21],[−126−3]→[4−21],[20−105]→[4−21]\displaystyle \begin{aligned} \begin{bmatrix} \point{8} \\ \point{-4} \\ \slide{2} \end{bmatrix} &\to \begin{bmatrix} \point{4} \\ \point{-2} \\ \slide{1} \end{bmatrix}, \\ \begin{bmatrix} \point{-12} \\ \point{6} \\ \slide{-3} \end{bmatrix} &\to \begin{bmatrix} \point{4} \\ \point{-2} \\ \slide{1} \end{bmatrix}, \\ \begin{bmatrix} \point{20} \\ \point{-10} \\ \slide{5} \end{bmatrix} &\to \begin{bmatrix} \point{4} \\ \point{-2} \\ \slide{1} \end{bmatrix} \end{aligned}
(Watch out: don't leave out [−126−3]\begin{bmatrix} \point{-12} \\ \point{6} \\ \slide{-3} \end{bmatrix} because of its signs, since dividing by w=−3\slide{w} = \slide{-3} flips the signs to [4−21]\begin{bmatrix} \point{4} \\ \point{-2} \\ \slide{1} \end{bmatrix}, and don't include [4−20]\begin{bmatrix} \point{4} \\ \point{-2} \\ \slide{0} \end{bmatrix} as a point just because its first two entries are 4\point{4} and −2\point{-2}.)
The vectors [8−42]\begin{bmatrix} \point{8} \\ \point{-4} \\ \slide{2} \end{bmatrix}, [−126−3]\begin{bmatrix} \point{-12} \\ \point{6} \\ \slide{-3} \end{bmatrix}, and [20−105]\begin{bmatrix} \point{20} \\ \point{-10} \\ \slide{5} \end{bmatrix} all lie on the same line through the origin and represent the 2D point (4,−2)\point{(4, -2)}, while [4−20]\begin{bmatrix} \point{4} \\ \point{-2} \\ \slide{0} \end{bmatrix} has w=0\slide{w} = \slide{0} and represents the 2D direction (4,−2)\point{(4, -2)}.
5

Find the single 3×33 \times 3 matrix that doubles the size of a 2D shape in place around its center at (3,−1)(3, -1), and use it to find where the corner (5,2)\point{(5, 2)} lands.

What three steps keep (3,−1)(3, -1) fixed at the origin during the scaling, and which slide goes on the right?

First slide (3,−1)(3, -1) to (0,0)(0, 0) by (−3,1)\slide{(-3, 1)} on the right, then double the size in the middle, and finally slide back by (3,−1)\slide{(3, -1)} on the left:
[10301−1001][200020001][10−3011001]=[20302−1001][10−3011001]=[20−3021001]\displaystyle \begin{aligned} & \begin{bmatrix} \first{1} & \second{0} & \slide{3} \\ \first{0} & \second{1} & \slide{-1} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \first{2} & \second{0} & \slide{0} \\ \first{0} & \second{2} & \slide{0} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix} \\ &\qquad \begin{bmatrix} \first{1} & \second{0} & \slide{-3} \\ \first{0} & \second{1} & \slide{1} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix} \\ &\quad = \begin{bmatrix} \first{2} & \second{0} & \slide{3} \\ \first{0} & \second{2} & \slide{-1} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \first{1} & \second{0} & \slide{-3} \\ \first{0} & \second{1} & \slide{1} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix} \\ &\quad = \begin{bmatrix} \first{2} & \second{0} & \slide{-3} \\ \first{0} & \second{2} & \slide{1} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix} \end{aligned}
(Watch out: swapping the two slides by putting (3,−1)(3, -1) on the right and (−3,1)(-3, 1) on the left gives [20302−1001]\begin{bmatrix} 2 & 0 & 3 \\ 0 & 2 & -1 \\ 0 & 0 & 1 \end{bmatrix}, which sends (5,2)(5, 2) to the wrong point (13,3)(13, 3).)
Apply this matrix to [521]\begin{bmatrix} \point{5} \\ \point{2} \\ \slide{1} \end{bmatrix}:
[20−3021001][521]=5[200]+2[020]+1[−311]=[751]\displaystyle \begin{aligned} & \begin{bmatrix} \first{2} & \second{0} & \slide{-3} \\ \first{0} & \second{2} & \slide{1} \\ \first{0} & \second{0} & \slide{1} \end{bmatrix}\begin{bmatrix} \point{5} \\ \point{2} \\ \slide{1} \end{bmatrix} = \first{5}\begin{bmatrix} \first{2} \\ \first{0} \\ \first{0} \end{bmatrix} \\ &\quad + \second{2}\begin{bmatrix} \second{0} \\ \second{2} \\ \second{0} \end{bmatrix}+ \slide{1}\begin{bmatrix} \slide{-3} \\ \slide{1} \\ \slide{1} \end{bmatrix} = \begin{bmatrix} \point{7} \\ \point{5} \\ \slide{1} \end{bmatrix} \end{aligned}
The corner lands at (7,5)\point{(7, 5)}.
6

A 3D point at (6,−3,2)(6, -3, \depth{2}) is first slid by (2,5,2)\slide{(2, 5, 2)} in 3D space and then projected onto the 2D screen by the 4×44 \times 4 perspective matrix. Multiply the two 4×44 \times 4 matrices into one matrix, apply it to [6−321]\begin{bmatrix} 6 \\ -3 \\ \depth{2} \\ \slide{1} \end{bmatrix}, and divide by w\slide{w} to find where the point lands on the 2D screen.

Where is the 11 located in the bottom row of the 4×44 \times 4 perspective matrix so that it copies the new depth z\depth{z} into the w\slide{w} slot?

Multiply the perspective matrix on the left by the 3D translation matrix on the right:
[1000010000100010][1002010500120001]=[1002010500120012]\displaystyle \begin{bmatrix} \first{1} & \second{0} & \depth{0} & \slide{0} \\ \first{0} & \second{1} & \depth{0} & \slide{0} \\ \first{0} & \second{0} & \depth{1} & \slide{0} \\ \first{0} & \second{0} & \depth{1} & \slide{0} \end{bmatrix}\begin{bmatrix} \first{1} & \second{0} & \depth{0} & \slide{2} \\ \first{0} & \second{1} & \depth{0} & \slide{5} \\ \first{0} & \second{0} & \depth{1} & \slide{2} \\ \first{0} & \second{0} & \depth{0} & \slide{1} \end{bmatrix} = \begin{bmatrix} \first{1} & \second{0} & \depth{0} & \slide{2} \\ \first{0} & \second{1} & \depth{0} & \slide{5} \\ \first{0} & \second{0} & \depth{1} & \slide{2} \\ \first{0} & \second{0} & \depth{1} & \slide{2} \end{bmatrix}
Multiply this combined matrix by [6−321]\begin{bmatrix} 6 \\ -3 \\ \depth{2} \\ \slide{1} \end{bmatrix}:
[1002010500120012][6−321]=[8244]\displaystyle \begin{bmatrix} \first{1} & \second{0} & \depth{0} & \slide{2} \\ \first{0} & \second{1} & \depth{0} & \slide{5} \\ \first{0} & \second{0} & \depth{1} & \slide{2} \\ \first{0} & \second{0} & \depth{1} & \slide{2} \end{bmatrix}\begin{bmatrix} 6 \\ -3 \\ \depth{2} \\ \slide{1} \end{bmatrix} = \begin{bmatrix} 8 \\ 2 \\ \depth{4} \\ \depth{4} \end{bmatrix}
Divide the vector by w=4\slide{w} = \depth{4}:
[8244]→[21211]\displaystyle \begin{bmatrix} 8 \\ 2 \\ \depth{4} \\ \depth{4} \end{bmatrix} \to \begin{bmatrix} 2 \\ \tfrac{1}{2} \\ 1 \\ \slide{1} \end{bmatrix}
(Watch out: stopping before the division by w=4\slide{w} = \depth{4} gives (8,2)(8, 2), and dividing by the original depth z=2\depth{z} = \depth{2} instead of the new depth w=4\slide{w} = \depth{4} gives (4,1)(4, 1).)
The point lands at (2,12)(2, \tfrac{1}{2}).