Brain Dump

Matrix Transformations

Tags
math

Applying a matrix to a vector (or collection of vectors) is the same as applying a transformation to those vectors. Warn: Matrix multiplication can only do rotation, reflection, shear & stretch transformations.

For example if he have the points \( (1,0)^T \) and \( (0,1)^T \) and the matrix \( \begin{pmatrix} 3 & 0 \\ 0 & 3 \end{pmatrix} \), then

\begin{align*} \begin{pmatrix}

3 & 0 \\\\
0 & 3

\end{pmatrix}

    \begin{pmatrix}
      1 & 0 \\\\
      0 & 1
    \end{pmatrix}
          =
          \begin{pmatrix}
            3 & 0 \\\\
            0 & 3
          \end{pmatrix}

\end{align*}

Observe that multiplying by this new matrix scales the vectors by 3.

Note: to multiply a matrix by a list of vectors/coordinates we place the each coordinate on a column in a new matrix and then multiply the result. The output matrix has the new coordinate position on each column.

We can define similar transformations for

  • rotation: A clockwise rotation of \(90^{\degree}\) \[ \begin {pmatrix} 0 & 1 \\ -1 & 0 \end{pmatrix} \]
  • reflection: Of \( y = x \) \[ \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} \]
  • reflection: Of \( y = 0 \) \[ \begin{pmatrix} -1 & 0 \\ 0 & 1 \end{pmatrix} \]

Constructing Transformations

We can create a matrix \( M = \begin{pmatrix} a & b \\ c & d \end{pmatrix} \) where \( (a, c) \) is the mirror image of \( (1, 0) \) and \( (b,d) \) is the mirror image of \( (0,1) \). We then plot where these mirror points will end up after the transformation and substitute the result back into our graph to get a matrix for this transformation. This works because setting \( a,b,c,d \) to the points described makes \( M \) the identity matrix. Applying the transformation to those points independently and then constructing a new matrix from the result is equivalent to multiplying the identity matrix by the transformation which is just the transformation.

This can be seen in fig:creating-trans.

\begin{figure}[ht]
  \centering
  \incfig{20210618164607}
  \label{fig:creating-trans}
  \caption{Demonstration of the principle of defining a matrix from a known
transformation on the points \( (1,0) \) and \( (0,1) \). The transformation shown
here is \( \begin{pmatrix} 0 & -1 \\ -1 & 0 \end{pmatrix} \) which is equivalent to a
reflection across \( y = -x \). This corresponds to the final coordinates of the
points after the transformation.}
\end{figure}

Translation

To support translations with matrix multiplication we add an extra dimension to the matrix and the vector that is always 1. Then we can offset each axis by a specific amount.

\begin{align*} \begin{pmatrix}

1 & 0 & t\_x \\\\
0 & 1 & t\_y \\\\

\end{pmatrix} \begin{pmatrix}

v\_x \\\\
v\_y \\\\
1

\end{pmatrix}

  &=
    \begin{pmatrix}
      v\_x + t\_x \\\\
      x\_y + t\_y \\\\
      1
    \end{pmatrix}

\end{align*}

Combining Transformations

You can also combine multiple transformation matrices by just multiplying them together. For example a matrix scale \( \begin{pmatrix} 3 & 0 \\ 0 & 3 \end{pmatrix} \) followed by a translation \( \begin{pmatrix} 0 & -1 \\ -1 & 0 \end{pmatrix} \) is equivalent to the combined transformation matrix

\begin{align*} \begin{pmatrix}

3 & 0 \\\\
0 & 3

\end{pmatrix}

    \begin{pmatrix}
      0 & -1 \\\\
      -1 & 0
    \end{pmatrix} &=
                    \begin{pmatrix}
                      0 & -3 \\\\
                      -3 & 0
                    \end{pmatrix}

\end{align*}

Recall the order of matrix multiplication is non-commutative. Depending on the transformation the order in which we multiply the associated matrices could have a different affect on the output positions.