Why?
Because understanding the underlying math is what separates someone who uses graphics from someone who builds it. These are the two most fundamental transforms in 3D graphics, and they're worth deriving from scratch at least once.
Translation Matrix
We want to move a 3D point (x, y, z) by adding displacement values (tx, ty, tz). In homogeneous coordinates a point becomes a 4×1 vector with a final component of 1.
The translation matrix is a 4×4 identity with the translation values in the top-right column:
| 1 0 0 tx | | x | | x + tx |
| 0 1 0 ty | * | y | = | y + ty |
| 0 0 1 tz | | z | | z + tz |
| 0 0 0 1 | | 1 | | 1 |
The homogeneous coordinate (the fourth component = 1) is what makes this multiplication work. Without it, you cannot represent translation as a matrix multiply — which is why homogeneous coordinates exist.
Rotation Matrices
Using polar coordinates and trigonometric identities, we can derive rotation matrices for each axis. The key identity:
cos(phi + theta) = cos(phi)*cos(theta) - sin(phi)*sin(theta)
sin(phi + theta) = sin(phi)*cos(theta) + cos(phi)*sin(theta)
Z-axis rotation
Rotates points in the xy-plane while preserving z:
| cos(t) -sin(t) 0 0 |
| sin(t) cos(t) 0 0 |
| 0 0 1 0 |
| 0 0 0 1 |
X-axis rotation
Preserves x, rotates in the yz-plane:
| 1 0 0 0 |
| 0 cos(t) -sin(t) 0 |
| 0 sin(t) cos(t) 0 |
| 0 0 0 1 |
Y-axis rotation
Preserves y, rotates in the xz-plane (note the sign flip vs X rotation):
| cos(t) 0 sin(t) 0 |
| 0 1 0 0 |
| -sin(t) 0 cos(t) 0 |
| 0 0 0 1 |
Composing Transforms
Because all transforms are represented as 4×4 matrices, they compose through multiplication. The standard order for a Model matrix is Scale × Rotate × Translate (applied right to left). This is the M in the MVP matrix used in every vertex shader.
Once you understand the derivation, the MVP stops being a magic incantation and becomes a sequence of coordinate space changes you can reason about.