Euler Angles
Ask a pilot how their aircraft is oriented and they won't hand you a
rotation matrix
— they'll say "nose up ten degrees, banked thirty to the left, heading north-east". Those three
plain-English numbers are Euler angles: yaw, pitch and roll. They are the most
human-readable way to name an orientation, and — for exactly the same reason — one of the most
persistent sources of bugs in a game engine.
Three turns about three axes
The idea is to reach any orientation by three successive axis rotations, each with its own
intuitive name.
Step 1 — yaw: turn about the up axis. Like shaking your head "no", this swings
the heading left and right. Taking up as z, yaw by
\psi is
R_z(\psi) = \begin{bmatrix} \cos\psi & -\sin\psi & 0 \\ \sin\psi & \cos\psi & 0 \\ 0 & 0 & 1 \end{bmatrix}.
Step 2 — pitch: tip about the right axis. Like nodding "yes", this raises and
lowers the nose. Taking right as y, pitch by
\theta is
R_y(\theta) = \begin{bmatrix} \cos\theta & 0 & \sin\theta \\ 0 & 1 & 0 \\ -\sin\theta & 0 & \cos\theta \end{bmatrix}.
Step 3 — roll: bank about the forward axis. Like tilting your head toward a
shoulder, this banks left and right. Taking forward as x, roll by
\phi is
R_x(\phi) = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos\phi & -\sin\phi \\ 0 & \sin\phi & \cos\phi \end{bmatrix}.
Multiply them into one orientation
Step 4 — compose the three rotations. The full orientation is the
matrix product
of the three elementary spins:
R = R_z(\psi)\,R_y(\theta)\,R_x(\phi).
Step 5 — read the order right-to-left. Applied to a vector
\mathbf{v}, the rightmost matrix acts first:
R\,\mathbf{v} = R_z(\psi)\,\Big(R_y(\theta)\,\big(R_x(\phi)\,\mathbf{v}\big)\Big),
so the object is rolled, then pitched, then yawed. Order and axis convention
matter. Because 3-D rotations don't commute (see
composing transformations),
R_z R_y R_x and R_x R_y R_z give
different orientations from the very same three angles. There is no universal
convention: one engine yaws first, another rolls first; one calls up z,
another calls it y. Reading another team's Euler angles without
knowing their convention is a reliable way to fly a spaceship into a wall.
An orientation can be specified by three angles applied as successive axis rotations:
-
yaw about the up axis, pitch about the right axis,
roll about the forward axis;
-
the full rotation is the product of the three elementary matrices, e.g.
R = R_z(\psi)\,R_y(\theta)\,R_x(\phi);
-
the result is order- and convention-dependent — different multiplication
orders or axis labels give different orientations from the same three numbers;
-
they are wonderfully human-readable (three intuitive angles), which is
why artists, designers and pilots all reach for them.
Euler angles are a joy to author. A designer scrubbing three sliders in an editor — yaw,
pitch, roll — gets instant, legible control over an orientation, and a keyframe of three
numbers is trivial to store and to interpolate by eye. For posing a streetlamp or animating
a turret, nothing beats them.
Engines, though, treat them warily, and not only for the ordering trap above. Stack the
rotations a certain way and two of the three axes can line up, collapsing three independent
dials into two — the orientation loses a whole degree of freedom and the controls fight each
other. That failure has a name,
gimbal lock,
and it is the reason engines convert Euler angles to a matrix or a quaternion the moment the
artist looks away. Read them in, compute with something better.
Pose an object
Drag the three sliders and watch the little frame take its orientation, shown in isometric
projection. The rotation applied is R_z(\psi)\,R_y(\theta)\,R_x(\phi):
roll first, then pitch, then yaw. Notice how the same three numbers, combined in this fixed
order, name one orientation — and imagine the confusion if another engine multiplied them the
other way around.