skip to content

With Euler angles, what is gimbal lock, and why does a yaw-pitch-roll flight camera lose a degree of freedom when it pitches straight up?

level: juniorimportance: must knowfreq 72%

answer

  1. three rotations applied in a fixed order
  2. the middle angle at its limit
  3. first and third axes line up
  4. every pose reachable, one direction of motion lost

basics

~20 s

Gimbal lock is the singularity of every three-angle Euler sequence: at pitch of plus or minus 90 degrees the yaw and roll axes line up, so both spin the camera about one axis and a degree of freedom disappears.

solid answer

~50 s

Euler angles store an orientation as three rotations applied in a fixed order. Take a flight camera that yaws about world up, then pitches about its own right axis, then rolls about its own forward axis. Pitching to 90 degrees points the forward axis straight up, onto the yaw axis, so yaw and roll now turn the camera about the same line and no small change of any angle turns it about its own up axis. Every orientation is still reachable; what is lost is one direction of motion near that pose, so smooth motion can demand huge angle jumps and the view snaps. Every three-angle order has such a pose, so reordering only moves it. The fixes are to clamp pitch short of 90 degrees when roll is not needed, or to keep the orientation itself as a quaternion or matrix and apply small rotations about local axes.

go deeper

for a junior

Recall that Euler angles are three rotations in a fixed order and that gimbal lock is two of those axes lining up when the middle angle reaches its limit.

for a middle

Walk through the flight-camera sequence and show which two axes coincide at 90 degrees of pitch, and say why clamping pitch is enough for a camera with no roll.

for a senior

Separate the parameterisation from the state: explain why a quaternion built from stored angles still locks, and how storing the orientation and applying local increments removes the problem.

for a principal

Decide where Euler angles are allowed, such as editor display and authored data, and where orientation must live as quaternions, and make the conversion boundary explicit for the team.

## Four ways to store a rotation A 3D rotation has three degrees of freedom, but games store it in several forms, each with its own strengths: | Representation | Numbers stored | Composing two | Interpolating | Weak spot | |---|---|---|---|---| | Euler angles | 3 | convert first | per-angle lerp is unreliable | gimbal lock, order ambiguity | | Axis-angle | 4 (or 3 as angle times axis) | convert first | fine for one rotation | axis undefined at angle 0 | | Rotation matrix | 9 | matrix product | needs re-orthonormalising | drift, more storage | | Unit quaternion | 4 | quaternion product | slerp or nlerp | q and -q are one rotation | Euler angles win on readability: a designer can type "pitch 30, yaw 45". That is why editors show them, and why they are a poor choice for the orientation state the game actually updates. ## What Euler angles actually encode Euler angles are three angles plus an **order** and a choice of **intrinsic** (each rotation about the object's current, already-rotated axes) or **extrinsic** (each about the fixed world axes). The same three numbers mean different orientations under different orders. Two facts help: - An intrinsic sequence equals the extrinsic sequence in reverse order with the same angles, so "intrinsic yaw, pitch, roll" and "extrinsic roll, pitch, yaw" describe the same matrix. - Sequences with three different axes (often called Tait-Bryan angles) lock when the **middle** angle reaches plus or minus 90 degrees; sequences that repeat an axis (classical Euler angles) lock when the middle angle is 0 or 180 degrees. ## Why the axes line up Assume a y-up world and a camera that applies, intrinsically, yaw about the up axis, then pitch about its local right axis, then roll about its local forward axis. 1. Yaw turns the camera's forward and right axes around world up. 2. Pitch tilts forward toward world up. At exactly 90 degrees, the camera's forward axis **is** world up. 3. Roll now rotates about forward, which is the same line yaw rotates about. 4. Yaw and roll have become one control: adding 10 degrees of yaw and subtracting 10 of roll leaves the camera unchanged. 5. The direction of motion that remains unavailable is a turn about the camera's own up axis, which now lies horizontal. This is the mathematical cousin of a physical gimbal, where three nested rings lose a degree of freedom when two of their axes become parallel. ## What is lost, and what is not - **Not lost:** any orientation. Every orientation still has Euler angles; near the lock it simply has infinitely many. - **Lost:** smoothness. Near the singular pose a small change of orientation can require a large change in yaw and roll, so per-angle interpolation or integration produces sudden spins. - **Not caused by floating point:** the singularity is in the parameterisation itself, at exact arithmetic. - **Not removed by reordering:** any sequence of three single-axis angles has a singular pose somewhere; a different order moves it to where it hurts less. ## Fixes that work, and one that does not - **Clamp pitch** to a little under 90 degrees. For a first-person camera with no roll this is the standard, honest solution: the singular pose is never reached. - **Store the orientation as a quaternion** (or a matrix) and apply each frame's input as a small rotation about the camera's local axes by multiplying it on. The state has no singular pose, so a flight camera can loop freely. - **Convert to Euler angles only for display**, accepting that the displayed numbers may jump near the singular pose. - **What does not work:** keeping yaw, pitch and roll as the state and building a quaternion from them every frame. The quaternion is exact, but it inherits the singularity of the three angles it was built from, because the angles are still what the input edits. In an interview, the strong answer separates two ideas candidates often blur: gimbal lock is a property of the **three-angle parameterisation**, not of matrices or of rotation itself, and quaternions help because the game stops storing angles, not because quaternions are magic.

  • Does a first-person shooter camera need quaternions to avoid gimbal lock?
    Usually not. A camera with yaw and pitch but no roll can store the two angles and clamp pitch a little short of 90 degrees, so the singular pose is never reached and the angles stay easy to read. Quaternions earn their place when the camera must reach any orientation, as in a flight or space game, or when orientations are composed and interpolated freely.
  • Why does lerping each Euler angle separately give bad in-between orientations even away from the singular pose?
    The three angles are not independent coordinates on the space of rotations: the orientation each produces depends on the others through the order of application. Lerping them separately follows a path that is generally not the shortest arc, its angular speed varies, and the result depends on the order chosen. Rotation interpolation is done on quaternions with slerp or nlerp instead.

A camera on a pan-and-tilt tripod head: tilt it to point straight up and panning no longer swings the view sideways, it only spins the picture about the lens; the camera can still be aimed anywhere, but one way of moving the view has gone.

  • Gimbal lock means some orientations cannot be represented at all.
  • Gimbal lock is caused by floating-point rounding in rotation matrices.
  • Choosing a different rotation order removes gimbal lock entirely.
  • Building a quaternion from stored yaw, pitch and roll each frame fixes it.
  • Rotation matrices suffer from gimbal lock just like Euler angles.