Week 02 | Day 04
Euler Angles vs Quaternions: Representing 3D Orientation in Robotics
Published: 2026-04-09 | Author: Smartotics Learning Journey | Reading Time: 7 min
Figure 1: Gimbal Lock visualization comparing normal 3-DOF gimbal with gimbal-locked 2-DOF state
Quick Summary
There are two main ways to represent 3D orientation in robotics: Euler angles (3 angles: roll, pitch, yaw — intuitive but problematic) and quaternions (4 numbers — less intuitive but robust). Rotation matrices are the mathematically clean representation but are bulky (9 numbers). Every robotics system uses all three, and knowing when to use each is critical.
Euler Angles: Intuitive but Tricky
Euler angles describe orientation as three sequential rotations around the X, Y, and Z axes, commonly called:
- Roll (φ): Tilt left/right (rotation about X)
- Pitch (θ): Nose up/down (rotation about Y)
- Yaw (ψ): Turn left/right (rotation about Z)
Why Euler Angles Are Popular
- Intuitive: everyone understands “tilt 10 degrees to the right”
- Minimal: only 3 numbers
- Easy to display and interpret
- Used by joysticks, game controllers, IMUs
The Problem: Gimbal Lock
Gimbal Lock: When One Degree of Freedom Is Lost
When pitch reaches 90° (nose straight up), roll and yaw become the same rotation. You lose one degree of freedom. This is called gimbal lock.
Real-world impact: During the Apollo 11 mission, the spacecraft’s IMU hit gimbal lock. A third gimbal had to be added. Every aerospace system since then uses quaternions to avoid this.
In a robot, gimbal lock means the controller can’t distinguish between roll and yaw — the robot might spin unexpectedly when the wrist approaches the critical configuration.
Multiple Representations: A Hidden Bug
Euler angles can represent the same orientation in multiple ways (e.g., [180, 0, 180] = [0, 0, 0] for ZYX convention). This makes it hard to compare orientations or interpolate smoothly between them.
Quaternions: The Robust Solution
A quaternion is a 4-tuple: q = [w, x, y, z] where w is the scalar part and [x, y, z] is the vector part. It encodes a rotation of angle θ around axis (x, y, z):
w = cos(θ/2) x = axis_x * sin(θ/2) y = axis_y * sin(θ/2) z = axis_z * sin(θ/2)
Why Quaternions Win
| Property | Euler Angles | Quaternions |
|---|---|---|
| Gimbal lock | ❌ Vulnerable | ✅ Immune |
| Smooth interpolation | ❌ Not smooth | ✅ SLERP (smooth) |
| Compact | ✅ 3 numbers | ❌ 4 numbers |
| Intuitive | ✅ Roll/pitch/yaw | ❌ [w,x,y,z] |
| Computation | ✅ Simple | ✅ Also simple |
Where Each Representation Is Used
| Representation | Where You’ll See It |
|---|---|
| Rotation Matrix (3x3) | Kinematic calculations, mathematics |
| Euler Angles (3) | Human-machine interfaces, IMU outputs, displays |
| Quaternions (4) | ROS (tf2), game engines, internal calculations, 3D graphics |
Best Practice
Use quaternions internally for all calculations, and convert to Euler angles only for human-facing outputs (displays, user input). Never store orientation as Euler angles if you need to do math with them.
Conversions (Reference)
You’ll frequently need to convert between all three representations. Here’s the flow:
Euler Angles (roll, pitch, yaw) ↓ (multiply 3 rotation matrices) Rotation Matrix (3x3) ↓/↑ (mathematical derivation) Quaternion [w, x, y, z]
The good news: you don’t need to memorize the conversion formulas. Libraries like scipy.spatial.transform.Rotation (Python), Eigen (C++), and tf2 (ROS2) handle them.
The important thing is understanding why you’re converting and which representation is right for each task.
FAQ
Q: Gimbal lock sounds scary. How often does it happen in practice?
For a ground-based robot arm, gimbal lock is rare because joints rarely hit exactly 90 degree pitch. But for drones, spacecraft, or humanoid robot heads, it’s a real concern. Always use quaternions for the internal math.
Q: Why does ROS use quaternions instead of Euler angles?
Because tf2 (the ROS coordinate transform system) needs smooth interpolation and gimbal-lock-free rotation. Quaternions provide both.
Q: Can I just always use rotation matrices and never worry about the others?
You could, but rotation matrices have 9 numbers (redundant) and are harder to debug. Quaternions (4 numbers) are the best compromise: compact, robust, and efficient.
Key Takeaways
Disclaimer
For educational purposes only. This article is part of a structured learning curriculum and does not constitute professional engineering advice.
Image Credits: All images are AI-generated illustrations for blog purposes only. © 2026 Smartotics Learning Journey.