3D Rotation and Euler Angles
Euler angles describe any 3D orientation as three turns in a row about the coordinate axes: yaw, pitch and roll. They're easy to read and treacherous to animate, because the order of the turns matters, the same orientation has many sets of angles and, at a pitch of , two of the three turns become the same turn: gimbal lock.
What the symbols mean
- Angle
Counterclockwise as you look down the x-axis toward the origin.
What the symbols mean
- Angle
Counterclockwise looking down the y-axis: it carries z toward x, so a positive β tips x down.
What the symbols mean
- Angle
Counterclockwise seen from above.
What the symbols mean
- Yaw
Turning left or right about the vertical axis.
- Pitch
Tipping the nose; with z up, a negative pitch is nose up.
- Roll
Tilting about the nose.
Explanation
Euler angles describe how something is turned in 3D using three angles, one for each of three simple turns done one after another about the coordinate axes. They're named after Leonhard Euler, who showed that three such turns are always enough to reach any orientation. For an airplane (or a game camera, or your head) the three turns have friendly names: yaw (turning left or right, like shaking your head no), pitch (tipping the nose up or down, like nodding) and roll (tilting about the nose, like resting your head on your shoulder). The formula is just those three turns written as matrices and multiplied. Each one is the 2D rotation from Rotating in 2D with a added for the axis that stays put, so there's less new here than it looks.
Our axes. We'll put up, the nose along and the left wing along . Every turn is counterclockwise when you look down its axis from the positive end toward the origin; that's the right-hand rule (curl the fingers of your right hand in the direction of the turn and your thumb points along the axis). Plenty of software puts up instead, and the letters move around, but nothing about the ideas changes. Always check your engine's convention before typing in angles.
One axis at a time. leaves alone and does the 2D rotation to and . does the same to and . is the one that looks off: its minus sign sits in the bottom-left corner. That's not a typo. Going counterclockwise around carries toward (because ), so the 2D rotation runs from to instead of from to , and the sign lands in the other corner. One consequence with our axes: a positive pitch tips the nose down, toward , so "nose up " is a pitch of .
Order matters. Grab a book. Turn it about the vertical axis, then about the axis pointing at you. Now start over and do the same two turns in the other order. The book ends up in two different positions, which is the matrix fact : matrix multiplication doesn't commute. There's an animation further down that does exactly this with two airplanes.
In the matrix next to the vector acts first: . So the airplane rolls first, then pitches, then yaws, all about the fixed world axes. Read the same product from left to right and you get the pilot's description instead: yaw, then pitch about the airplane's new wing, then roll about its new nose. Both readings describe the same matrix. Multiplied out, it is
Its first column is where the nose goes: . Notice roll isn't in it at all. Rolling spins the plane about its own nose, so the nose doesn't move. Going backward from a matrix to angles: , and .
A common mistake. Writing the matrices in the order the turns happen. If a vector is turned by and then by , the result is : the first turn goes on the right, next to the vector. Write and you've done the turns in the opposite order, which, as the book shows, is a different orientation.
Gimbal lock. Now set the pitch to , nose straight up. Then and , and using the angle-sum formulas on the entries, the big matrix collapses to
Only the sum appears. Yaw and roll have become the same turn, about the vertical axis that the nose now points along, and there's no angle left that tips the plane sideways from here. Three angles, but only two ways to move: that missing direction is gimbal lock. The name comes from real gimbals, nested rings that each pivot inside the next (gyroscopes, camera stabilizers, telescope mounts). Swing the middle ring and the inner ring's axis lines up with the outer ring's. Nothing is physically broken; it's the three-angle description that fails, and every three-angle scheme fails somewhere. That's one reason the next lesson switches to quaternions.
Why lerping Euler angles wobbles. It's tempting to animate an orientation by lerping its three angles, the way you'd lerp a position. Two things go wrong. First, one orientation has many angle triples: (yaw , pitch , roll ) is exactly the same orientation as (yaw , pitch , roll ), and lerping toward one or the other gives two completely different motions. Whichever triple your tools happen to store decides what the audience sees. Second, even when the path is sensible, the three angles are tangled together inside the matrix, so steady changes in the angles don't make a steady turn: the object speeds up, slows down and drifts sideways in between. Near gimbal lock it's worst, because a small change in orientation can require a huge change in yaw and roll, and the lerp dutifully spins through all of it. Slerp fixes all of this.
In code, the nose direction is the line most games need from all this:
// where the nose points, for yaw psi and pitch theta (z up, nose along x, positive pitch = nose down)
const nose = [Math.cos(theta) * Math.cos(psi), Math.cos(theta) * Math.sin(psi), -Math.sin(theta)];
See it
Worked examples
A drone's nose points along and its top along . Apply and then, separately, to both. Where do the nose and top end up each time?
- 1
At , and , so the three matrices we need become simple. sends : it leaves alone and does a quarter turn in the - plane.
Show that an airplane at pitch with yaw and roll has exactly the same orientation as one with yaw , pitch and roll .
- 1
Use the full matrix written out entry by entry, and put in : and .
Practice
Type your answer and check it. Solve them all to complete the lesson.
Turn the vector by , a quarter turn counterclockwise about the -axis. Enter the result.
Turn the vector by , using . Enter the result.
Compute : turn the vector by about the -axis first, then by about the -axis.
A camera drone uses yaw-pitch-roll angles with up and its nose along at rest. It's set to yaw , pitch (nose up ) and roll . Which unit vector does its nose point along?
A rotation in yaw-pitch-roll form (with ) has first column . Find the yaw and pitch in degrees. Enter .
An aircraft in a flight simulator is at pitch (nose straight up) with yaw and roll , using . Which yaw angle, with the same pitch and a roll of , gives exactly the same orientation? Answer in degrees.
Which set of (yaw, pitch, roll) angles gives the same orientation as yaw , pitch , roll , using ?
Euler's rotation theorem says the product is a single turn about one axis. The angle of that turn satisfies , where is the sum of the diagonal entries. Multiply out and find in degrees.
The hardest one here. Get it, and you've got this lesson.
A telescope on a yaw-pitch mount tracks a satellite that passes from straight overhead. Near the top of the sky, treat the view as flat: measured in degrees from straight up, the satellite is at at time seconds, so it crosses the sky at per second. The mount's yaw is the compass direction . How fast must the yaw turn at , in degrees per second?
Where it's used
Flight simulators, drone autopilots and game cameras all show yaw, pitch and roll to people, because humans think that way: "turn left , nose up ." Camera rigs in games usually store just yaw and pitch, clamp the pitch to about so the camera never reaches gimbal lock, and rebuild the rotation from the two angles each frame. Robot arms and telescope mounts are physical gimbals, and their controllers plan around the lock: a two-axis tracking antenna loses a satellite passing straight overhead unless it starts its yaw swing early. Behind the scenes, though, the orientation that gets animated and blended is usually a quaternion, the next lesson.