3D Rotations
In 3D, rotation is far richer than in 2D. Instead of a single angle, we need to describe orientation around three axes. This lesson covers the fundamental rotation matrices and the Euler angle representation — along with its infamous limitation.
Elementary Rotation Matrices
Rotation around X (Roll)
The x-axis stays fixed; the y-z plane rotates.
Rotation around Y (Pitch)
The y-axis stays fixed; the x-z plane rotates. Note the sign pattern: appears in position (0,2) and in (2,0) — opposite to and . This is required by the right-hand rule: the cyclic order means the y-axis rotation “wraps around” differently. Getting this sign wrong is one of the most common bugs in manual 3D rotation code.
Rotation around Z (Yaw)
The z-axis stays fixed; the x-y plane rotates. Notice this is the 2D rotation matrix embedded in 3D.
Properties of 3D Rotation Matrices
- (orthogonal — same as 2D)
- (proper rotation, not reflection)
- Preserves lengths and angles
- The set of all 3×3 rotation matrices forms the Special Orthogonal group SO(3)
Euler Angles
Any 3D rotation can be decomposed into three sequential rotations around the coordinate axes. The most common convention in robotics is ZYX (yaw-pitch-roll):
where:
- Roll (): rotation around X — tilting sideways
- Pitch (): rotation around Y — tilting forward/backward
- Yaw (): rotation around Z — turning left/right
Think of an airplane: roll banks the wings, pitch raises or lowers the nose, and yaw turns the heading.
Convention Mismatch — A Common Bug Source
There are 12 valid Euler angle conventions (6 Tait-Bryan like ZYX, and 6 proper Euler like ZXZ). Different software uses different ones:
- ROS: RPY (XYZ fixed-axis, equivalent to ZYX body-axis)
- Unity: ZXY
- Unreal Engine: ZYX
- Aerospace: Often ZYZ
Convention mismatch is one of the most common bugs in robotics software. When using any library, always check its Euler angle convention in the documentation before combining rotations from different sources.
Drone Orientation Robotics Application
A quadrotor drone uses roll, pitch, and yaw to describe its attitude (orientation in space):
- Roll tilts the drone sideways → moves left/right
- Pitch tilts the drone forward/backward → moves forward/backward
- Yaw rotates the drone’s heading → turns in place
The flight controller reads gyroscope and accelerometer data from the IMU (Inertial Measurement Unit) and computes the rotation matrix to determine the drone’s current orientation. The control loop then adjusts motor speeds to achieve the desired attitude.
Gimbal Lock
Euler angles have a critical limitation called gimbal lock. When the pitch angle reaches , the yaw and roll axes become aligned, and one degree of freedom is lost.
What happens mathematically
When pitch , the rotation matrix maps the x-axis into the z-axis direction (specifically, to ). Now both (yaw) and (roll) rotate around the same axis — they become redundant. Only their sum or difference matters:
Notice that only appears — we cannot independently control yaw and roll. We’ve lost a degree of freedom.
Gimbal Lock in Practice
Gimbal lock caused real problems in the Apollo program’s inertial measurement unit, which used physical gimbals. When two gimbal rings aligned, the platform could tumble unpredictably.
In modern robotics, gimbal lock can cause:
- Sudden jumps in computed orientation
- Numerical instability in control algorithms
- Singularities in path planning
This is why many robotics systems use quaternions (covered in Module 4) instead of Euler angles for orientation representation. Quaternions are based on the axis-angle idea: by Euler’s rotation theorem, any rotation can be described by a single axis and angle — a more natural representation than three sequential rotations.
Rotation Matrix Properties
A valid 3D rotation matrix must satisfy two conditions:
- Orthogonality: (columns are orthonormal)
- Proper rotation: (not a reflection)
A 3×3 rotation matrix has 9 elements but only 3 degrees of freedom. The six independent orthogonality constraints (, a symmetric 3×3 equation with 6 independent entries) reduce the 9 elements to 3 free parameters. The determinant condition further restricts to proper rotations, excluding reflections (where ).
Numerical Drift in Practice
When rotation matrices are composed repeatedly (e.g., integrating gyroscope data in a control loop), floating-point rounding errors accumulate. The matrix gradually stops being orthogonal — drifts away from . Left unchecked, this causes the “rotation” to include shearing and scaling artifacts.
Solution: Periodically re-orthogonalize the matrix using Gram-Schmidt orthogonalization or SVD projection back onto SO(3). Most robotics frameworks handle this automatically, but it’s important to understand why.
End-Effector Orientation Robotics Application
A 6-DOF robot arm’s end-effector orientation is described by a 3×3 rotation matrix. When programming a pick-and-place task, you specify:
- Position: where the gripper should be
- Orientation: how the gripper should be rotated (rotation matrix )
For example, to pick up a horizontally-lying bolt, the gripper might need to approach from above with a specific wrist rotation. The robot’s inverse kinematics solver must find joint angles that achieve both the target position and the target rotation matrix.
Composing 3D Rotations
The same right-to-left rule applies: applies first, then , then .
3D rotations are not commutative: .
Try it yourself: take a book, rotate it 90° around the x-axis (tilt forward) then 90° around the z-axis (turn left). Now start over and do z first, then x. The book ends up in a completely different orientation!
Interactive Visualization
Adjust the Euler angles to see how a 3D coordinate frame rotates. The rotation matrix updates in real-time. Try setting pitch to ±90° to observe gimbal lock — you’ll see the warning appear and notice that changing roll and yaw produces the same rotation.
Rotation Matrix R
| [ | 1.000 | 0.000 | 0.000 | ] |
| [ | 0.000 | 1.000 | 0.000 | ] |
| [ | 0.000 | 0.000 | 1.000 | ] |
Euler Angles (ZYX)
Try this: Set pitch to exactly 90° and then change roll and yaw — notice they produce the same rotation (gimbal lock). The world frame (large axes) stays fixed while the rotated frame (smaller) moves.
Practice Problems
-
What is the rotation matrix for a 90° rotation around the Z axis?
-
If you apply then , what direction does the original Y-axis unit vector end up pointing?
-
At what pitch angle(s) does gimbal lock occur with the ZYX Euler convention?
Answers
-
-
First apply : (y-axis maps to z-axis). Then apply : (z-axis is unchanged by z-rotation). So the result is — the original y-axis ends up pointing along z.
-
Gimbal lock occurs at pitch ( radians). At these angles, the yaw and roll axes align, and one degree of freedom is lost.
Key Takeaways
- Elementary rotations , , each rotate around one coordinate axis
- Euler angles (ZYX convention) decompose any rotation into yaw, pitch, roll
- Gimbal lock occurs when pitch = ±90°, causing loss of one degree of freedom
- Rotation matrices are orthogonal with , having only 3 DOF despite 9 elements
- 3D rotation composition is non-commutative — order matters even more than in 2D
Next Steps
We can now rotate objects in 3D, but how do we combine rotation and translation into a single operation? Homogeneous coordinates solve this elegantly — and they’re the standard representation used in all robotics software.