Developer15 min read

Euler Angles vs Quaternions: Understanding 3D Rotations Explained

Tags:Developer Tools3D GraphicsGame DevelopmentMath

Euler angles and quaternions are the two primary ways to represent rotation in 3D space, and choosing the wrong one can introduce gimbal lock, animation glitches, and hard-to-trace orientation bugs. This guide explains both representations, compares them directly, and walks through the practical details every game developer, robotics engineer, and 3D graphics programmer needs to know. You can experiment with both representations in real time using FindUtils' 3D Rotation Visualizer, which converts between Euler angles, quaternions, rotation matrices, and axis-angle on the fly.

What Are Euler Angles?

Euler angles describe a 3D rotation as three sequential rotations around coordinate axes, typically labeled pitch (X), yaw (Y), and roll (Z). Each angle specifies how far to rotate around one axis, and the three rotations are applied in a specific order to produce the final orientation.

The appeal of Euler angles is immediate: they map directly to how humans think about rotation. "Tilt forward 30 degrees, turn right 45 degrees, roll 10 degrees" is intuitive and easy to edit in an inspector panel. This is why every major game engine displays rotations as Euler angles in its editor, even when storing them differently under the hood.

However, Euler angles have two fundamental problems:

  • Order dependence -- rotating 30 degrees around X then 45 degrees around Y produces a different result than 45 around Y then 30 around X. The rotation order is not interchangeable.
  • Gimbal lock -- at certain angles, two axes align and one degree of freedom is lost. This is not a software bug. It is a mathematical property of representing 3D rotation with three sequential angles.

The rotation order also varies by convention. Aerospace commonly uses ZYX, robotics uses ZYZ, and game engines each pick their own default. Getting the order wrong silently produces incorrect orientations -- one of the most common rotation bugs in cross-engine work.

The Gimbal Lock Problem

Gimbal lock occurs when the middle rotation in an Euler angle sequence reaches +90 or -90 degrees, causing the first and third rotation axes to align. At that point, changing either the first or third angle produces the same physical rotation, effectively collapsing three degrees of freedom into two.

This is not a theoretical curiosity. Gimbal lock has caused real-world engineering failures:

  • Apollo 13 (1970) -- The Apollo spacecraft used a three-gimbal inertial measurement unit. Engineers added a fourth gimbal to avoid lock, but the command module's three-gimbal design still required careful attitude management to keep the middle gimbal away from 90 degrees.
  • Game cameras -- A first-person camera using Euler angles will "flip" or freeze when looking straight up or down (pitch = 90 degrees). The yaw and roll axes collapse into the same rotation, and the camera loses the ability to turn left or right smoothly.
  • Robotic arms -- A 6-DOF robotic arm can encounter gimbal lock in its wrist joints when two joint axes align, causing singularity in the Jacobian matrix and loss of controllability.

You can observe gimbal lock directly in FindUtils' 3D Rotation Visualizer: set the pitch (X) to exactly 90 degrees with the default XYZ order, then try adjusting yaw and roll. You will see that both sliders produce the same physical rotation -- one degree of freedom has vanished.

What Are Quaternions?

A quaternion is a four-component mathematical object written as q = w + xi + yj + zk, where w is the scalar part and (x, y, z) is the vector part. When a quaternion has unit length (w^2 + x^2 + y^2 + z^2 = 1), it represents a rotation in 3D space.

Quaternions encode a rotation as "rotate by angle theta around axis (ax, ay, az)" using the formula:

1
2
3
4
w = cos(theta/2)
x = ax * sin(theta/2)
y = ay * sin(theta/2)
z = az * sin(theta/2)

This representation has several critical advantages over Euler angles:

  • No gimbal lock -- quaternions do not pass through a sequential-axis decomposition, so there is no configuration where axes can align and collapse.
  • Compact storage -- 4 floats instead of 9 (rotation matrix) or 3+order (Euler).
  • Stable composition -- multiplying two unit quaternions produces another unit quaternion representing the combined rotation. No numerical drift accumulates the way it does with repeated matrix multiplications.
  • Smooth interpolation -- SLERP (Spherical Linear Interpolation) produces constant-speed rotation along the shortest arc between two orientations.

The downside is that quaternions are unintuitive. Looking at (0.707, 0.0, 0.707, 0.0) does not immediately tell you "90 degrees around the Y axis" the way Euler angles would. This is why engines display Euler angles in their editors while storing quaternions internally.

Euler Angles vs Quaternions: Head-to-Head Comparison

The choice between Euler angles and quaternions depends on what you are doing. This table summarizes the key differences:

FeatureEuler AnglesQuaternions
Components3 angles + rotation order4 values (w, x, y, z)
Intuitive to readYes -- pitch/yaw/roll are human-friendlyNo -- four abstract numbers
Gimbal lockYes -- occurs at +/-90 degree pitchNo -- immune to gimbal lock
Smooth interpolationPoor -- LERP causes wobble and artifactsExcellent -- SLERP is constant-speed
CompositionRequires converting to matrix firstDirect multiplication (q1 * q2)
Storage size3 floats + order enum4 floats
Normalization neededNo (angles are always valid)Yes -- must stay unit-length
Editor-friendlyYes -- sliders map to axesNo -- editing raw values is impractical
Use in shaders/GPURare -- converted to matrix firstSometimes, but usually via matrix
Industry standardAerospace (ZYX), animation curvesGame engines, robotics, physics

Rule of thumb: Use Euler angles for human-facing UI and serialization formats where readability matters. Use quaternions for runtime computation, interpolation, and anywhere gimbal lock would be a problem.

Rotation Matrices and Axis-Angle: The Other Options

Euler angles and quaternions are the most common representations, but two others appear frequently in graphics and robotics.

Rotation Matrices

A 3x3 rotation matrix explicitly describes where each basis vector (X, Y, Z) ends up after the rotation. Each column of the matrix is the transformed axis direction. Matrices are the native language of GPUs and physics engines -- vertex shaders apply rotation by multiplying position vectors by a matrix.

Rotation matrices have 9 values (vs. 4 for quaternions), but they compose naturally via matrix multiplication and require no special interpolation logic. The tradeoff is size and the risk of numerical drift: after thousands of multiplications, a rotation matrix can slowly stop being orthogonal, requiring periodic re-orthogonalization.

Axis-Angle

The axis-angle representation stores a rotation as a unit direction vector (ax, ay, az) and a scalar angle theta. It maps directly to the physical intuition of "rotate this much around this direction" and is closely related to quaternions -- converting between them is a single trigonometric operation.

Axis-angle is useful for:

  • Specifying rotations in physics simulations (angular velocity is naturally an axis-angle quantity)
  • User interfaces where "rotate 45 degrees around the up vector" is the natural mental model
  • Compact logging and debugging

Both representations are available in FindUtils' 3D Rotation Visualizer, which shows the equivalent rotation matrix and axis-angle pair alongside the Euler and quaternion values.

SLERP: Why Quaternion Interpolation Matters

SLERP (Spherical Linear Interpolation) is the standard method for smoothly blending between two quaternion rotations. Given quaternions q1 and q2 and a parameter t from 0 to 1, SLERP traces the shortest arc on the 4D unit sphere at constant angular velocity.

Why does this matter? Consider animating a camera from orientation A to orientation B:

  • Linear interpolation of Euler angles produces uneven speed, wobble, and potential gimbal lock mid-transition. The camera may take an unexpected path through 3D space.
  • SLERP of quaternions produces a smooth, constant-speed rotation along the shortest possible path. No wobble, no surprises, no gimbal lock.

This is why every animation system in production game engines -- Unity's Animator, Unreal's Sequencer, Godot's AnimationPlayer -- stores keyframe rotations as quaternions and interpolates with SLERP. Even if you author keyframes using Euler angle curves, the engine converts to quaternions before blending.

SLERP is also critical for:

  • Character animation blending -- smoothly transitioning between walk and run cycles
  • Inverse kinematics -- interpolating joint rotations for procedural animation
  • Camera systems -- orbiting, following, and cinematographic transitions
  • Robotics path planning -- generating smooth joint trajectories

Rotation Orders in Major Game Engines

One of the most common cross-engine rotation bugs is assuming all engines use the same Euler angle order. They do not. Each engine has its own convention, and importing rotations between them without accounting for order differences will produce wrong orientations.

Engine / LibraryDefault Euler OrderNotes
UnityZXY (intrinsic)Inspector shows X/Y/Z but applies in ZXY order
Unreal EngineZYXStored as FRotator (pitch/yaw/roll), converted to FQuat internally
Three.jsXYZConfigurable via euler.order, default is 'XYZ'
GodotYXZSimilar to Unity's convention
BlenderXYZSupports all 6 orders in the rotation mode selector
glTF formatQuaternion onlyNo Euler angles in the spec -- always quaternion
USD (Pixar)XYZUses xformOp:rotateXYZ by default

When exporting rotations from one engine to another, always convert through quaternions first. Quaternions are order-independent, so they serve as a universal intermediate format. FindUtils' 3D Rotation Visualizer lets you switch between all 12 Euler orders (XYZ, XZY, YXZ, YZX, ZXY, ZYX and their extrinsic counterparts) and see the equivalent quaternion, making cross-engine conversion straightforward.

How to Convert Between Euler Angles and Quaternions

Step 1: Open the 3D Rotation Visualizer

Go to FindUtils' 3D Rotation Visualizer. The tool displays Euler angle sliders, quaternion inputs, the rotation matrix, and axis-angle values -- all synchronized in real time.

Step 2: Set Your Rotation Order

Select the Euler angle order that matches your source engine or convention. For Unity, choose ZXY. For Three.js, choose XYZ. For Unreal, choose ZYX. Getting this wrong is the single most common conversion mistake.

Step 3: Enter Your Rotation Values

Type your Euler angle values (in degrees) into the pitch, yaw, and roll fields. The quaternion, rotation matrix, and axis-angle fields update instantly. Alternatively, paste a quaternion and see the equivalent Euler angles.

Step 4: Check for Gimbal Lock

The tool warns you when your Euler angles are near gimbal lock (middle axis near +/-90 degrees). If you see a gimbal lock warning, the Euler-to-quaternion conversion is still correct, but the reverse (quaternion back to Euler) may produce unexpected angle values -- this is expected behavior, not a bug.

Step 5: Export in Your Target Format

Use the Copy Format buttons to export the rotation as Unity C# (Quaternion(x, y, z, w)), Unreal C++ (FQuat(x, y, z, w)), glTF JSON, or CSS rotate3d() syntax. Paste directly into your codebase.

Common Mistakes with 3D Rotations

Mistake 1: Using the Wrong Rotation Order

Applying XYZ rotations to data that was authored in ZXY order silently produces incorrect orientations. Always verify the rotation order of your source and target systems. Unity uses ZXY, Unreal uses ZYX, and Three.js uses XYZ -- these are not interchangeable.

Mistake 2: Forgetting to Normalize Quaternions

A quaternion must have unit length to represent a valid rotation. After manual editing, arithmetic operations, or network transmission, quaternion components can drift from unit length. Always normalize after modification: q_normalized = q / |q|. Non-unit quaternions produce scaling and shearing artifacts, not just wrong rotations.

Mistake 3: Interpolating Euler Angles Directly

Linearly interpolating between two sets of Euler angles does not produce a smooth rotation. It can cause the shortest-path assumption to fail, introduce gimbal lock mid-interpolation, and produce wildly uneven angular velocity. Always convert to quaternions and use SLERP.

Mistake 4: Ignoring Gimbal Lock in Animation Curves

Authoring animation keyframes as Euler angle curves works fine for small rotations, but breaks down when the character needs to look straight up, flip upside down, or rotate more than 180 degrees. If your animation system stores Euler curves, it will need to "unwrap" angles and may still produce artifacts near gimbal lock orientations.

Mistake 5: Assuming Quaternion Double Cover Does Not Matter

Every 3D rotation corresponds to two quaternions: q and -q (the negation of all four components). Both represent the same rotation. If your code compares quaternions without accounting for this, distance calculations and SLERP can take the long way around (360 minus the intended angle). Always check the dot product of two quaternions before interpolating -- if it is negative, negate one before SLERP.

Tools Used in This Guide

  • 3D Rotation Visualizer -- Convert between Euler angles, quaternions, rotation matrices, and axis-angle in real time with gimbal lock detection
  • 3D Vector Visualizer -- Visualize 3D vectors and understand the coordinate systems that underpin rotation representations
  • 3D Model Viewer -- Inspect glTF/GLB models and verify that exported rotations render correctly in a WebGL viewport
  • Unit Converter -- Convert between degrees and radians, which is essential since most rotation math uses radians internally

FAQ

Q1: What is the difference between Euler angles and quaternions? A: Euler angles represent a 3D rotation as three sequential rotations around coordinate axes (pitch, yaw, roll), making them intuitive but vulnerable to gimbal lock. Quaternions use four components (w, x, y, z) to represent rotation without gimbal lock, enabling smooth interpolation via SLERP. Game engines store rotations as quaternions internally but display Euler angles in their editors for usability.

Q2: What is gimbal lock and how do I avoid it? A: Gimbal lock happens when the middle axis in an Euler angle sequence reaches +/-90 degrees, causing two rotation axes to align and collapsing three degrees of freedom into two. You avoid it by using quaternions for runtime rotation storage and interpolation. If you must use Euler angles, keep the middle axis well away from 90 degrees or switch to quaternion-based logic when approaching that range.

Q3: Which rotation order does Unity use? A: Unity uses ZXY intrinsic rotation order for Euler angles. The Inspector panel shows X, Y, and Z fields, but internally it applies Z first, then X, then Y. Unreal Engine uses ZYX, Three.js defaults to XYZ, and Godot uses YXZ. Always match the rotation order to your engine when converting between formats.

Q4: Is there a free tool to convert Euler angles to quaternions online? A: Yes. FindUtils' 3D Rotation Visualizer converts between Euler angles, quaternions, rotation matrices, and axis-angle representations in real time. It supports all 12 Euler angle orders and exports rotations in Unity, Unreal, glTF, and CSS formats -- all free, with no signup required and all processing done in your browser.

Q5: Why does SLERP produce smoother rotations than linear interpolation? A: SLERP (Spherical Linear Interpolation) moves along the surface of a 4D unit sphere at constant angular velocity, always taking the shortest path between two orientations. Linear interpolation of Euler angles moves through angle-space in a straight line, which does not correspond to a shortest-path rotation in 3D space. This causes variable speed, wobble, and potential gimbal lock during the interpolation.

Q6: Can I use Euler angles in production game code? A: Euler angles are fine for user-facing input (like a level editor rotation field) and for serialization where human readability matters. For runtime rotation logic -- especially interpolation, composition, and physics -- always use quaternions. Most engines provide conversion functions (Quaternion.Euler() in Unity, FRotator::Quaternion() in Unreal) to bridge between the two.

Q7: What happens if a quaternion is not normalized? A: A non-normalized quaternion does not represent a pure rotation. Applying it to a vector will introduce scaling and shearing in addition to rotation, producing distorted geometry. After any arithmetic operation on quaternion components (addition, manual editing, network deserialization), always normalize the result by dividing each component by the quaternion's length.

Next Steps

Mastering 3D rotations is one piece of the larger 3D math puzzle. To continue building your understanding:

  • Explore vector math fundamentals with the 3D Vector Visualizer -- understanding dot products, cross products, and coordinate spaces makes rotation math far more intuitive
  • Inspect how rotations are stored in actual 3D assets using the 3D Model Viewer -- load a glTF file and examine the node transforms
  • Practice converting angle units between degrees and radians with the Unit Converter -- nearly all rotation APIs use radians internally, and mixing up units is a classic bug source
  • Bookmark the 3D Rotation Visualizer for the next time you need to debug a rotation value or convert between engines