Mathematics
Quaternions vs. Matrices for Representing Rotations in 3D Space
Quick fact
Quaternions require only 4 numbers to represent a rotation, while a rotation matrix needs 9—yet quaternions avoid a notorious failure mode called gimbal lock that can make Euler-angle systems freeze up.
Why this is interesting
You can rotate an object in 3D using a 3×3 matrix or a 4‑number quaternion. Both do the same job, so why do animators and spacecraft engineers ditch matrices for quaternions?
Read the full explanation
Understanding Quaternions vs. Matrices for Representing Rotations in 3D Space
Imagine you have a toy spaceship and you want to spin it in any direction. One way is to use a rotation matrix: a 3×3 grid of numbers that, when multiplied by a vector describing a point on the ship, gives you the new position after rotation. It’s like a set of instructions that tell each coordinate where to go. Another way is to use a quaternion—a 4‑tuple of numbers (w, x, y, z) that encodes the rotation as a spin around a specific axis. Quaternions can be thought of as an extension of complex numbers, but with three imaginary components instead of one. Both methods can describe any 3D rotation, but they have different properties: a matrix has 9 numbers that must satisfy six constraints to stay a valid rotation, while a quaternion is valid as long as its length is 1. This difference leads to practical trade-offs in computation, memory, and flexibility.
A deeper explanation
The key to comparing quaternions and matrices lies in how they compose and interpolate. When you rotate an object by two rotations in sequence, you multiply their matrices or multiply their quaternions. Matrix multiplication is associative, so composition works, but it requires 9 multiplications per combine and suffers from numerical drift: after many operations, the matrix can become non-orthogonal (no longer a pure rotation). Quaternion multiplication uses only 4 numbers and is more stable, because you can re‑normalize after each step. More importantly, interpolating between two orientations is much harder with matrices: a simple linear interpolation of the 9 numbers gives a matrix that is not a rotation. Quaternions allow smooth, reliable interpolation using spherical linear interpolation (slerp), which is perfect for camera animations. This advantage—efficiency, compactness, and ease of interpolation—makes quaternions the go‑to choice in 3D graphics, robotics, and aerospace navigation, even though matrices are still essential for other transformations like scaling and shearing.