In computer graphics, matrices are fundamental tools used to transform objects in 2D and 3D space. These transformations include translation, rotation, and scaling . This page explains how matrices enable these operations with mathematical examples and an interactive app.
Before diving into transformations, we need to understand homogeneous coordinates. In a 3D system, we represent a point as \((x, y, z, 1)\) and a vector as \((x, y, z, 0)\). This allows us to represent both transformations and translations using matrices.
Translation moves an object by a displacement vector \((t_x, t_y, t_z)\). The translation matrix is:
For a point \(P = (x, y, z, 1)\), the translated point \(P'\) is:
Rotation transforms an object around an axis. Here are rotation matrices for the three primary axes:
Rotation around X-axis by angle \(\theta\):
Rotation around Y-axis by angle \(\theta\):
Rotation around Z-axis by angle \(\theta\):
Scaling changes the size of an object by factors \((s_x, s_y, s_z)\). The scaling matrix is:
In practice, we often apply multiple transformations in sequence. Matrix multiplication allows us to combine these operations efficiently.
Let's consider rendering a cube with vertices at \((\pm 1, \pm 1, \pm 1)\).
We want to transform a cube as follows:
The composite transformation matrix would be:
\[ M = T(10, 5, -3) \cdot R_y(45^\circ{}) \cdot S(2, 1, 0.5) \]Substituting the matrices:
\[ M = \begin{pmatrix} 1 & 0 & 0 & 10 \\ 0 & 1 & 0 & 5 \\ 0 & 0 & 1 & -3 \\ 0 & 0 & 0 & 1 \end{pmatrix} \cdot \begin{pmatrix} \cos(45^{\circ}) & 0 & \sin(45^{\circ}) & 0 \\ 0 & 1 & 0 & 0 \\ -\sin(45^{\circ}) & 0 & \cos(45^{\circ}) & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \cdot \begin{pmatrix} 2 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0.5 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \]Using \(\cos(45^{\circ}) = \sin(45^{\circ}) = \frac{\sqrt{2}}{2} \approx 0.7071\):
\[ M = \begin{pmatrix} 1 & 0 & 0 & 10 \\ 0 & 1 & 0 & 5 \\ 0 & 0 & 1 & -3 \\ 0 & 0 & 0 & 1 \end{pmatrix} \cdot \begin{pmatrix} 0.7071 & 0 & 0.7071 & 0 \\ 0 & 1 & 0 & 0 \\ -0.7071 & 0 & 0.7071 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \cdot \begin{pmatrix} 2 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0.5 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \]Multiplying the last two matrices first:
\[ R_y(45^{\circ}) \cdot S(2, 1, 0.5) = \begin{pmatrix} 1.4142 & 0 & 0.3536 & 0 \\ 0 & 1 & 0 & 0 \\ -1.4142 & 0 & 0.3536 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \]Then multiplying with the translation matrix:
\[ M = \begin{pmatrix} 1.4142 & 0 & 0.3536 & 10 \\ 0 & 1 & 0 & 5 \\ -1.4142 & 0 & 0.3536 & -3 \\ 0 & 0 & 0 & 1 \end{pmatrix} \]Applying all the three transformations to the vertex \( (1,1,1) \) for example, we obtain a new vertex at : \[ M \cdot \begin{pmatrix} 1 \\ 1 \\ 1 \\ 1 \end{pmatrix} = \begin{pmatrix} 1.4142 & 0 & 0.3536 & 10 \\ 0 & 1 & 0 & 5 \\ -1.4142 & 0 & 0.3536 & -3 \\ 0 & 0 & 0 & 1 \end{pmatrix} \cdot \begin{pmatrix} 1 \\ 1 \\ 1 \\ 1 \end{pmatrix} = \begin{pmatrix}11.7678\\ 6\\ -4.0606\\ 1\end{pmatrix} \]
Note: In computer graphics, transformations are typically applied from right to left in matrix multiplication, contrary to the order we'd describe the operations in English.
Matrices provide an elegant and efficient way to represent and combine transformations in computer graphics. By using homogeneous coordinates and matrix multiplication, we can easily implement complex 3D scenes with rotation, translation, and scaling, all fundamental operations in modern rendering engines.
The power of the matrix approach is that any sequence of transformations can be combined into a single matrix, which can then be efficiently applied to all vertices in a 3D model.
In computer graphics, matrices are fundamental tools used to transform objects in 2D and 3D space. This interactive demonstration allows you to explore how different transformations affect a 3D object and see the corresponding matrices.
Transform the cube that is in the screen by rotating, translating and scaling it. Use one transformation at the time in order to better understand each transformation. The transformation matrices are also displayed at the bottom of the page.
Before diving into transformations, we need to understand homogeneous coordinates. In a 3D system, we represent a point as \((x, y, z, 1)\) and a vector as \((x, y, z, 0)\). This allows us to represent both transformations and translations using matrices.
Translation moves an object by a displacement vector \((t_x, t_y, t_z)\). The translation matrix is:
Rotation transforms an object around an axis. Here are rotation matrices for the three primary axes:
Rotation around X-axis by angle \(\theta\):
Rotation around Y-axis by angle \(\theta\):
Rotation around Z-axis by angle \(\theta\):
Scaling changes the size of an object by factors \((s_x, s_y, s_z)\). The scaling matrix is: