Transformations
- Demo for today.
- This is sort of Section 2.3
- I think he is looking at non-math people.
- This is where linear algebra comes into play for me.
- Points
- We will represent points as a 3 or 4 tuple.
- For 2d: $[x, y, 1]$
- For 3d: $[x, y, z, 1]$
- This will make the next step work.
- Review matrix vector multiplication.
- $\begin{bmatrix} a & d & g \\
b & e & h \\
c & f & i
\end{bmatrix}
\times
\begin{bmatrix}x \\ y \\ z\end{bmatrix}
= [ ax + dy + gz, bx + ey + hz, cx + fy + iz] $
- Matrix matrix multiplication
- Remember $A \times B \neq B \times A $ in general.
- Translating in the plane
- We would like to move a point in the plane by $(t_x, t_y)$
- The simplest is to do $(x + t_x, y + t_y)$
- But linear gives us a cool system so let's try
- $\begin{bmatrix} 1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1 \end{bmatrix} \times \begin{bmatrix}x \\ y \\ 1\end{bmatrix} $
- This is the base 2d translation matrix.
- Scaling in the plane
- Again scale by $(s_x, s_y)$
- Which would be $(x \times s_x, y \times s_y)$
- $\begin{bmatrix} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & 1 \end{bmatrix} \times \begin{bmatrix}x \\ y \\ 1\end{bmatrix} $
- By the way, this scales about the origin.
- The neat part is that matrix multiplication preserves the order of the transformations.
- Let's try scale then translate
- $\begin{bmatrix} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & 1 \end{bmatrix} \times
\begin{bmatrix} 1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1 \end{bmatrix} =
\begin{bmatrix} s_x & 0 & s_x t_x \\
0 & s_y & s_y t_y \\
0 & 0 & 1 \\
\end{bmatrix}$
- Let's try translate then scale
- $\begin{bmatrix} 1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1 \end{bmatrix} \times
\begin{bmatrix} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & 1 \end{bmatrix} =
\begin{bmatrix} s_x & 0 & t_x \\
0 & s_y & t_y \\
0 & 0 & 1 \\
\end{bmatrix}$
- In the first case, we translate the point, then scale it.
- In the second we scale, then translate.
- In the first, the translation is also scaled, but not so in the second.