1. Why Use Matrices for 3D Transformations? Matrices are the most efficient and GPU-friendly way to store and apply transformations like translation, rotation, and scaling in 3D graphics. They allow complex operations to be executed quickly on hardware by reducing all transformations into matrix multiplications.
2. Linear Transformations vs. Translation A linear transformation is one that preserves the origin and satisfies the properties of additivity and homogeneity. Examples include:
However, translation is not linear — it moves all points by a constant offset and does not preserve the origin. This means you can't represent it using a 3x3 matrix.
3. Why Use a 4x4 Matrix?
To incorporate translation with other transformations (like rotation and scaling), we use homogeneous coordinates. This involves adding a fourth component (w
) to position vectors:
[x, y, z]
becomes [x, y, z, 1]
Using a 4x4 matrix, we can then represent translation, rotation, and scale together:
[ R11 R12 R13 Tx ]
[ R21 R22 R23 Ty ]
[ R31 R32 R33 Tz ]
[ 0 0 0 1 ]
This enables us to combine multiple transforms into a single matrix, and apply it using one multiplication.
4. Why This is GPU-Friendly Modern GPUs are designed to handle matrix operations efficiently. By representing transformations with 4x4 matrices:
vec4 position = modelMatrix * vec4(vertex, 1.0);