The majority of geometric operations used in computer graphics can be perform using matrix operations. Compound transformations can be implemented by simple multiplying matrices together to combine all the operation into a single matrix.

Identity

The identity matrix is the equivalent of no-operation.

\[\begin{pmatrix} 1 & 0 & 0 & 0\\\ 0 & 1 & 0 & 0\\\ 0 & 0 & 1 & 0\\\ 0 & 0 & 0 & 1 \end{pmatrix}\]

Translation

To translate by \((x,y,z)\)

\[\begin{pmatrix} 1 & 0 & 0 & x\\\ 0 & 1 & 0 & y\\\ 0 & 0 & 1 & z\\\ 0 & 0 & 0 & 1 \end{pmatrix}\]

Scale

To scale by \((x,y,z)\)

\[\begin{pmatrix} x & 0 & 0 & 0\\\ 0 & y & 0 & 0\\\ 0 & 0 & z & 0\\\ 0 & 0 & 0 & 1 \end{pmatrix}\]

Rotation

To rotate \(\theta\) radians around the X axis:

\[\begin{pmatrix} 1 & 0 & 0 & 0\\\ 0 & cos(\theta) & -sin(\theta) & 0\\\ 0 & sin(\theta) & cos(\theta) & 0\\\ 0 & 0 & 0 & 1 \end{pmatrix}\]

To rotate \(\theta\) radians around the Y axis:

\[\begin{pmatrix} cos(\theta) & 0 & sin(\theta) & 0\\\ 0 & 1 & 0 & 0\\\ -sin(\theta) & 0 & cos(\theta) & 0\\\ 0 & 0 & 0 & 1 \end{pmatrix}\]

To rotate \(\theta\) radians around the Z axis:

\[\begin{pmatrix} cos(\theta) & -sin(\theta) & 0 & 0\\\ sin(\theta) & cos(\theta) & 0 & 0\\\ 0 & 0 & 1 & 0\\\ 0 & 0 & 0 & 1 \end{pmatrix}\]

Note that 2D rotation is equivalent to rotation around the z axis, therefore removing the last row and last column from the matrix above yields a matrix that can be used for a 2D rotation.

Mirroring

To mirror across the X axis:

\[\begin{pmatrix} -1 & 0 & 0 & 0\\\ 0 & 1 & 0 & 0\\\ 0 & 0 & 1 & 0\\\ 0 & 0 & 0 & 1 \end{pmatrix}\]

To mirror across the Y axis:

\[\begin{pmatrix} 1 & 0 & 0 & 0\\\ 0 & -1 & 0 & 0\\\ 0 & 0 & 1 & 0\\\ 0 & 0 & 0 & 1 \end{pmatrix}\]

To mirror across the Z axis:

\[\begin{pmatrix} 1 & 0 & 0 & 0\\\ 0 & 1 & 0 & 0\\\ 0 & 0 & -1 & 0\\\ 0 & 0 & 0 & 1 \end{pmatrix}\]