9.2.6. Transformations

9.2.6.1. Transformation matrices

To transform a vector, we multiply the vector with a transformation matrix

\[\begin{split}\begin{pmatrix} x' \\ y' \end{pmatrix} = \mathbf{T} \begin{pmatrix} x \\ y \end{pmatrix}\end{split}\]

Usual transformation matrices in 2D are

\[\begin{split}\begin{align} \mathbf{Id} &= \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \\[1em] \mathbf{Scale}(s_x, s_y) &= \begin{bmatrix} s_x & 0 \\ 0 & s_y \end{bmatrix} \\[1em] \mathbf{Rotation}(\theta) &= \begin{bmatrix} \cos\theta & \sin\theta \\ -\sin\theta & \cos\theta \end{bmatrix} \\[1em] \end{align}\end{split}\]

For translation and affine transformation, we must introduce the concept of homogeneous coordinate which add a virtual third dimension:

\[\begin{split}\mathbf{V} = \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}\end{split}\]

Then the translation and affine transformation matrix are expressed as:

\[\begin{split}\begin{align} \mathbf{Translation}(t_x, t_y) &= \begin{bmatrix} 1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1 \end{bmatrix} \\[1em] \mathbf{Generic} &= \begin{bmatrix} r_{11} & r_{12} & t_x \\ r_{12} & r_{22} & t_y \\ 0 & 0 & 1 \end{bmatrix} \end{align}\end{split}\]

To compose transformations, we must multiply the transformations in this order:

\[\mathbf{T} = \mathbf{T_n} \ldots \mathbf{T_2} \mathbf{T_1}\]

Note the matrix multiplication is not commutative.