2D Transformation Matrices



Overview and application of bi-dimensional transformation matrices.

Translation


$$ \large x'=x + t_x \\ \large y'=y + t_y $$

using homogeneous matrix $$ \large \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1 \end{bmatrix}\begin{bmatrix} x \\ y \\ 1 \end{bmatrix} $$

translate

Scaling


Relative to the point $(p_x, p_y)$ $$ \large x'=s_x(x - p_x) + p_x = s_x x + p_x(1 - s_x)\\ \large y'=s_y(y - p_y) + p_y = s_y y + p_y(1 - s_y) $$ using homogeneous matrix $$ \large \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} s_x & 0 & p_x(1 - s_x) \\ 0 & s_y & p_y(1 - s_y) \\ 0 & 0 & 1 \end{bmatrix}\begin{bmatrix} x \\ y \\ 1 \end{bmatrix} $$

scale

Rotation


Relative to the point $(p_x, p_y)$ $$ \large x'=(x - p_x)\cos\beta-(y - p_y)\sin \beta + p_x = x \cos \beta - y \sin \beta + p_x(1 - \cos \beta) + p_y \sin \beta \\ \large y'=(x - p_x)\sin\beta+(y - p_y)\cos \beta + p_y = x \sin \beta + y \cos \beta + p_y(1 - \cos \beta) - p_x \sin \beta $$ using homogeneous matrix $$ \large \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} \cos\beta & -\sin\beta & p_x(1 - \cos \beta) + p_y \sin \beta \\ \sin\beta & \cos\beta & p_y(1 - \cos \beta) - p_x \sin \beta \\ 0 & 0 & 1 \end{bmatrix}\begin{bmatrix} x \\ y \\ 1 \end{bmatrix} $$

rotate

Shearing


Relative to the point $(p_x, p_y)$ $$ \large x' = x + \lambda_x(y - p_x) = x + \lambda_x y - \lambda_x p_x\\ \large y' = y + \lambda_y(x - p_y) = y + \lambda_y x - \lambda_y p_y $$ using homogeneous matrix $$ \large \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & \lambda_x & -\lambda_x p_x \\ \lambda_y & 1 & -\lambda_y p_y \\ 0 & 0 & 1 \end{bmatrix}\begin{bmatrix} x \\ y \\ 1 \end{bmatrix} $$

shear