3D Transformation Matrices



Overview and application of tri-dimensional transformation matrices.

Translation


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

using homogeneous matrix

$$ \large \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\ 0 & 0 & 1 & t_z \\ 0 & 0 & 0 & 1 \end{bmatrix}\begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} $$

translate

Scaling


Relative to the point $(p_x, p_y, p_z)$

$$ \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) \\ \large z'=s_z(z - p_z) + p_z = s_z z + p_z(1 - s_z) $$

using homogeneous matrix

$$ \large \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix} = \begin{bmatrix} s_x & 0 & 0 & p_x(1 - s_x) \\ 0 & s_y & 0 & p_y(1 - s_y) \\ 0 & 0 & s_z & p_z(1 - s_z) \\ 0 & 0 & 0 & 1 \end{bmatrix}\begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} $$

scale

Rotation


Relative to the point $(p_x, p_y, p_z)$ $$ \large R=R_x(\alpha)R_y(\beta)R_z(\gamma) $$

Rotation around the x-axis


$$ \large y'=(y - p_y)\cos\alpha-(z - p_z)\sin \alpha + p_y = y \cos \alpha - z \sin \alpha + p_y(1 - \cos \alpha) + p_z \sin \alpha \\ \large z'=(y - p_y)\sin\alpha+(z - p_z)\cos \alpha + p_z = y \sin \alpha + z \cos \alpha + p_z(1 - \cos \alpha) - p_y \sin \alpha $$

using homogeneous matrix

$$ \large \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos\alpha & -\sin\alpha & p_y(1 - \cos \alpha) + p_z \sin \alpha \\ 0 & \sin\alpha & \cos\alpha & p_z(1 - \cos \alpha) - p_y \sin \alpha \\ 0 & 0 & 0 & 1 \end{bmatrix}\begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} $$

Rotation around the y-axis


$$ \large x'=(x - p_x)\cos\beta+(z - p_z)\sin \beta + p_x = x \cos \beta + z \sin \beta + p_x(1 - \cos \beta) - p_z \sin \beta \\ \large z'=-(y - p_y)\sin\beta+(z - p_z)\cos \beta + p_z = -x \sin \beta + z \cos \beta + p_z(1 - \cos \beta) + p_x \sin \beta $$

using homogeneous matrix

$$ \large \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix} = \begin{bmatrix} \cos\beta & 0 & \sin\beta & p_x(1 - \cos \beta) - p_z \sin \beta \\ 0 & 1 & 0 & 0 \\ -\sin\beta & 0 & \cos\beta & p_z(1 - \cos \beta) + p_x \sin \beta \\ 0 & 0 & 0 & 1 \end{bmatrix}\begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} $$

Rotation around the z-axis


$$ \large x'=(x - p_x)\cos\gamma-(y - p_y)\sin \gamma + p_x = x \cos \gamma - y \sin \gamma + p_x(1 - \cos \gamma) + p_y \sin \gamma \\ \large y'=(x - p_x)\sin\gamma+(y - p_y)\cos \gamma + p_y = x \sin \gamma + y \cos \gamma + p_y(1 - \cos \gamma) - p_x \sin \gamma $$

using homogeneous matrix

$$ \large \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix} = \begin{bmatrix} \cos\gamma & -\sin\gamma & 0 & p_x(1 - \cos \gamma) + p_y \sin \gamma \\ \sin\gamma & \cos\gamma & 0 & p_y(1 - \cos \gamma) - p_x \sin \gamma \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}\begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} $$

rotate

Shearing


Relative to the point $(p_x, p_y, p_z)$

$$ \large x' = x + \lambda_x^y(y - p_x) + \lambda_x^z(z - p_x) = x + \lambda_x^y y + \lambda_x^z z - (\lambda_x^y + \lambda_x^z) p_x\\ \large y' = y + \lambda_y^x(x - p_y) + \lambda_y^z(z - p_y) = y + \lambda_y^x x + \lambda_y^z z - (\lambda_y^x + \lambda_y^z) p_y\\ \large z' = z + \lambda_z^x(x - p_z) + \lambda_z^y(y - p_z) = z + \lambda_z^x x + \lambda_z^y y - (\lambda_z^x + \lambda_z^y) p_z $$

using homogeneous matrix

$$ \large \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix} =\begin{bmatrix} 1 & \lambda_x^y & \lambda_x^z & -(\lambda_x^y + \lambda_x^z) p_x \\ \lambda_y^x & 1 & \lambda_y^z & -(\lambda_y^x + \lambda_y^z) p_y \\ \lambda_z^x & \lambda_z^y & 1 & -(\lambda_z^x + \lambda_z^y) p_z \\ 0 & 0 & 0 & 1 \end{bmatrix}\begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} $$

shear