Rotation Representations
In Module 3, we used Euler angles and rotation matrices to represent orientation. Both have significant drawbacks: Euler angles suffer from gimbal lock, and rotation matrices use 9 numbers with 6 redundant constraints. This lesson introduces representations that solve these problems — axis-angle, rotation vectors, and quaternions — the workhorses of modern robotics and 3D graphics.
Why Euler Angles Aren’t Enough
Quick recap of the problems (from Module 3):
-
Gimbal lock: When pitch = , roll and yaw become coupled — one degree of freedom is lost. The robot can still physically reach all orientations, but the mathematical representation becomes singular.
-
Non-unique representation: Multiple Euler angle triples can represent the same rotation (e.g., and with different conventions).
-
Interpolation artifacts: Linearly interpolating between two sets of Euler angles doesn’t produce a smooth, shortest-path rotation. The intermediate orientations can take bizarre detours.
-
12 conventions: The lack of a single standard means convention mismatches are inevitable in multi-library systems.
We need representations that are singularity-free, unique (or nearly so), and interpolation-friendly.
Axis-Angle Representation
Euler’s rotation theorem states that any 3D rotation can be described as a single rotation by angle about a fixed axis :
This is the rotation’s axis-angle form. It uses only 4 numbers (3 for the unit axis + 1 for the angle), compared to 9 for a rotation matrix.
Connection to Eigenvalues
From Lesson 1: a 3D rotation matrix always has eigenvalue , and the corresponding eigenvector is the rotation axis . The rotation angle can be recovered from the trace:
Axis-angle is the eigenvalue decomposition of rotations made explicit.
Axis-Angle to Rotation Matrix: Rodrigues’ Formula
Given axis and angle , the rotation matrix is:
where is the skew-symmetric matrix of :
This is Rodrigues’ rotation formula — one of the most important formulas in 3D geometry. A useful identity for the squared term: , which follows from the vector triple product .
Rotation About Z-Axis Robotics Application
Verify Rodrigues’ formula for a rotation by about (the z-axis):
Rotation Matrix to Axis-Angle
Given a rotation matrix :
-
Angle:
-
Axis (when ):
Degenerate Cases
- When : the rotation is the identity. The axis is undefined (any axis works for a zero rotation).
- When : , so the formula above fails. Instead, extract the axis from the eigenvector of corresponding to , or from the symmetric part: is proportional to any nonzero column of .
These edge cases matter in code — always handle them explicitly.
Rotation Vectors
The rotation vector packs the axis and angle into a single 3D vector:
- The direction of is the rotation axis
- The magnitude is the rotation angle
This is the most compact non-redundant representation — just 3 numbers for 3 DOF. It’s widely used in optimization and Lie group theory (where it parameterizes the tangent space of SO(3), called ).
The mapping from rotation vectors to rotation matrices is the matrix exponential:
and Rodrigues’ formula is precisely the closed-form evaluation of this exponential.
The inverse mapping (rotation matrix to rotation vector) is the matrix logarithm:
Small-Angle Approximation Robotics Application
For small rotations (), Rodrigues’ formula simplifies dramatically:
This linearization is used constantly in robotics:
- EKF-based SLAM: Orientation updates use small rotation vectors as the error state
- Visual odometry: Frame-to-frame rotation changes are small
- Jacobian computation: Relating joint velocities to angular velocities
The error is , so for ( rad), the approximation error is under 0.4%.
Quaternions
Quaternions are the gold standard for rotation representation in robotics, aerospace, and computer graphics. They use 4 numbers, are singularity-free, and enable efficient composition and interpolation.
Definition
A quaternion extends complex numbers with three imaginary units :
or equivalently, as a scalar-vector pair:
The imaginary units satisfy Hamilton’s rules: .
Unit Quaternions and Rotations
A unit quaternion () represents a rotation. Given axis and angle :
Note the half angle — this is key to how quaternions work. It means that a 360° rotation gives , not the identity . In fact, and represent the same rotation (double cover of SO(3)).
Why Half Angles?
The half-angle appears because quaternions provide a double cover of the rotation group SO(3). Both and map to the same rotation matrix. This double cover is what makes quaternions topologically able to avoid singularities — the unit quaternion sphere is simply connected, unlike SO(3) which has a nontrivial fundamental group.
In practice, this means: when comparing or interpolating quaternions, always check if and negate one if needed to ensure you take the shorter path.
Rotating a Vector with a Quaternion
To rotate a vector by the rotation represented by unit quaternion :
- Encode the vector as a pure quaternion:
- Compute:
- Extract the vector part of
where is the conjugate (which equals the inverse for unit quaternions).
Quaternion Multiplication
Two quaternions multiply as:
Composing rotations is just quaternion multiplication: if rotates and then rotates, the combined rotation is .
This is much cheaper than multiplying two matrices (16 multiplications + 12 additions for quaternions vs. 27 multiplications + 18 additions for matrices).
Quaternion to Rotation Matrix
Rotation Matrix to Quaternion
Given , the quaternion can be extracted via the Shepperd method (numerically stable):
- Compute
- If : , ,
- If : use alternative formulas based on the largest diagonal element
Quaternion Ordering Convention
This lesson uses scalar-first ordering: . However, many libraries use scalar-last: . Watch out:
- Scalar-first : Eigen (default), MATLAB, Aerospace convention
- Scalar-last : ROS tf2, Unity, PyBullet
Mixing conventions silently produces wrong rotations. Always check your library’s documentation — this is the quaternion equivalent of the Euler angle convention problem.
Quaternion Normalization
Like rotation matrices, quaternions accumulate numerical drift when composed repeatedly. Periodically re-normalize: . This is a simple division by the norm — much cheaper than re-orthogonalizing a matrix.
IMU Orientation Tracking Robotics Application
An IMU (Inertial Measurement Unit) outputs angular velocity at high frequency (e.g., 1000 Hz). To track orientation over time:
Update rule (first-order integration):
where
This is done in quaternion space — no Euler angles, no gimbal lock, and the normalization step keeps the quaternion on the unit sphere. Madgwick and Mahony filters (standard IMU orientation filters) work entirely in quaternion representation.
SLERP — Spherical Linear Interpolation
One of the most compelling reasons to use quaternions is SLERP (Spherical Linear intERPolation). Given two orientations and , SLERP produces a smooth, constant-angular-velocity interpolation:
where is the angle between the quaternions and .
Properties of SLERP:
- Constant angular velocity: the rotation rate is uniform throughout the interpolation
- Shortest path: it follows the great circle on the unit quaternion sphere (after ensuring )
- Torque-minimal: it minimizes the total angular acceleration
Robot Motion Planning Robotics Application
A pick-and-place robot needs to move its gripper from orientation (pointing down to grasp) to (tilted to insert a peg). Using SLERP:
for t = 0 to 1 step 0.01:
q_target = slerp(q_pick, q_place, t)
send_orientation_command(q_target)The result is a smooth, predictable rotation that:
- Takes the shortest path (no unnecessary spinning)
- Moves at constant angular velocity (no jerky accelerations)
- Never hits gimbal lock (regardless of the start/end orientations)
Compare this to interpolating Euler angles linearly, which can produce wobbly, non-shortest paths and may even fail entirely near gimbal lock configurations.
SLERP Edge Cases
- When (quaternions nearly identical): SLERP degenerates. Use linear interpolation (LERP) + normalization instead: .
- When : negate one quaternion before interpolating to ensure the shortest path (recall and are the same rotation).
Comparison of Representations
| Representation | Parameters | Singularities | Composition | Interpolation | Use Case |
|---|---|---|---|---|---|
| Euler Angles | 3 | Gimbal lock | Slow (matrix rebuild) | Poor | Human-readable configs |
| Rotation Matrix | 9 (6 constraints) | None | Matrix multiply | Difficult | Direct vector transformation |
| Axis-Angle | 4 (1 constraint) | Axis undefined at | Via Rodrigues | Non-trivial | Visualization, display |
| Rotation Vector | 3 | At | Via exponential | Additive (small angles) | Optimization, Lie theory |
| Quaternion | 4 (1 constraint) | None | Quaternion multiply | SLERP | Industry standard |
Which Should You Use?
The practical answer: use quaternions as your internal representation, convert to/from other forms as needed:
- Convert from Euler angles when reading human-authored configs
- Convert to rotation matrices when applying transforms to points
- Convert to axis-angle for visualization (showing the rotation axis and angle)
- Use rotation vectors for optimization problems and error representation
Every major robotics framework (ROS, Drake, MoveIt), game engine (Unity, Unreal), and physics simulator (Bullet, MuJoCo) uses quaternions internally.
Conversions Summary
Axis-Angle Quaternion
Axis-angle → Quaternion:
Quaternion → Axis-angle:
Quaternion Rotation Matrix
Use the formulas in the “Quaternion to Rotation Matrix” and “Rotation Matrix to Quaternion” sections above.
Rotation Vector Quaternion
Rotation vector → Quaternion: extract and , then apply axis-angle → quaternion.
Quaternion → Rotation vector: extract axis-angle from quaternion, then .
Current Quaternion
Try this: Scrub the SLERP slider from 0 to 1 and watch the box rotate smoothly along the shortest path. The colored dots trace the path of the X-axis tip — always a great-circle arc. Try different presets to see how SLERP handles various start/end orientations.
Practice Problems
-
Find the axis-angle representation of using the trace formula and axis extraction.
-
Use Rodrigues’ formula to compute the rotation matrix for a 180° rotation about axis .
-
Convert the axis-angle pair to a unit quaternion.
-
Compute where and .
-
Two orientations are represented as quaternions: (identity) and (180° about z). What is ?
Answers
-
. . Axis: . So: 90° about the z-axis. ✓
-
, so , . . With : . So . This swaps x and y and negates z.
-
.
-
Using : . . Result: .
-
. . Normalized: . This is a 90° rotation about z — exactly halfway between 0° and 180°. ✓
Module 4 Complete!
Congratulations! You’ve mastered the advanced mathematical tools of robotics:
- Eigenvalues & eigenvectors — for stability analysis, PCA, and understanding manipulability
- Coordinate frames — for managing multi-sensor systems and transformation chains
- Rotation representations — quaternions for singularity-free, interpolation-friendly orientation control
Next module: We’ll bring everything together in Module 5: Applications, applying these tools to real robotics problems — inverse kinematics, trajectory planning, and more!