Rotations, Quaternions, and SO(3)

When we model movement or control robotic systems, we are not looking at the physical object itself; we are tracking a Coordinate Frame rigidly attached…

Rotations, Quaternions, and SO(3)

Note

Rotations are everywhere in mechanics—every joint in a robot arm rotates, every satellite tumbles, every golf club sweeps through an arc. But rotations are mathematically strange in a way that catches everyone off guard the first time.

Here is the surprise: the order of rotations matters. If you rotate a book 90 degrees around the vertical axis, then 90 degrees around the horizontal axis, you get a different result than if you do those same two rotations in the opposite order. Try it right now with a book on your desk. This is not true for translations (walking 3 steps north then 2 steps east ends up the same as 2 east then 3 north).

This non-commutativity means rotations do not live in ordinary Euclidean space. They live on a curved surface called \(SO(3)\)—the group of all rotations. This chapter introduces that surface and its properties. The payoff is enormous: by respecting the geometry of rotations, we avoid the singularities and artifacts that plague simpler representations like Euler angles.

The Coordinate Frame

When we model movement or control robotic systems, we are not looking at the physical object itself; we are tracking a Coordinate Frame rigidly attached to the object, often denoted as the Body Frame (\(B\)).

To know where the Body Frame \(B\) is relative to the absolute stationary universe—the Spatial (or World) Frame (\(S\))—we must define two mathematical properties: 1. The translation vector \(\bm{p} \in \Reals^3\) pointing from the origin of \(S\) to the origin of \(B\). 2. The rotation of the axes of \(B\) relative to the axes of \(S\).

Unlike the straightforward \((X, Y, Z)\) translation vector, rotation is profoundly mathematically problematic.

Euler Angles and Gimbal Lock

The most intuitive way to describe the orientation of an aircraft, drone, or robotic arm is to split rotation into three successive angles around axes, usually denoted as Roll, Pitch, and Yaw (\(X, Y, Z\)).

This is known as an Euler Angle representation: \(\bm{\theta} = [\theta_1, \theta_2, \theta_3]^T\). While highly intuitive for a human pilot, Euler Angles harbor a fatal mathematical flaw known as Gimbal Lock.

Note

If an airplane pitches perfectly \(90^\circ\) straight up into the sky, its Roll axis (pointing out its nose) now perfectly aligns with its original Yaw axis (pointing perfectly down towards the Earth).

Mathematically, two independent degrees of freedom have become linearly dependent—they merged into the identical physical rotation axis. A degree of freedom is literally lost during the calculation. If you attempt to control the plane passing through this “Singularity”, your matrices become non-invertible and your computer instantly crashes mapping a physical impossibility.

Since our control theory and geometric motion algorithms fundamentally rely on continuous trajectories twisting through all possible spatial angles (like chaotic golf club arcs or throwing motions), we must completely abandon Euler angles. We cannot afford mathematical singularities.

The Special Orthogonal Group: SO(3)

To map 3D orientation without singularities in all continuous space, we define a rotation by looking at the purely physical unit vectors defining the Body Frame \(B\): the \(\hat{x}_b, \hat{y}_b, \hat{z}_b\) axes.

If we write these three body axes explicitly in the coordinates of the Space Frame \(S\), we can stack them vertically into a \(3 \times 3\) matrix: \[\begin{equation} R = \begin{bmatrix} | & | & | \\ \hat{x}_b & \hat{y}_b & \hat{z}_b \\ | & | & | \end{bmatrix} \in \Reals^{3 \times 3} \end{equation}\]

This is a Rotation Matrix.

Because \(\hat{x}_b, \hat{y}_b,\) and \(\hat{z}_b\) are all length \(1\) (unit magnitude) and perfectly orthogonal (all \(90^\circ\) apart), the columns are an orthonormal basis. The strict mathematical definitions that guarantee this orthonormality are: 1. \(R^T R = I\) (The transpose equals the inverse) 2. \(\det(R) = 1\) (The determinant is 1 to preserve right-handed orientation—no reflecting through a mirror)

Note

The continuous, infinite geometric space of all possible valid \(3 \times 3\) rotation matrices satisfying \(R^T R = I\) and \(\det(R) = 1\) is a mathematical manifold called the Special Orthogonal Group in 3 Dimensions, denoted as \(\SO\).

If a Configuration Space \(\configspace\) is simply a rigid body rotating around a point, we say \(\configspace = \SO\).

Unit Quaternions \(\mathcal{H}\)

While \(\SO\) completely prevents Gimbal Lock and provides pure, continuous rotation matrices, tracking 9 entries inside a \(3 \times 3\) grid (only 3 of which are independent) is wildly computationally inefficient for an engine updating a 15-DOF human model at 1,000 Hertz.

To solve this, William Rowan Hamilton invented Quaternions (\(\mathcal{H}\)) in 1843. Rather than tracking a full Cartesian body frame \(R \in \SO\), any 3D rotation can be flawlessly described as a combination of precisely two things: 1. A single unit vector \(\hat{\bm{\omega}}\) defining the solitary physical axis of rotation. 2. An angle \(\theta\) denoting how far to spin around that axis.

A Unit Quaternion \(q\) mathematically encodes these into 4 variables representing an exponential scalar and vector map: \[\begin{equation} q = \begin{bmatrix} q_0 \\ q_1 \\ q_2 \\ q_3 \end{bmatrix} = \begin{bmatrix} \cos(\theta/2) \\ \hat{\bm{\omega}}_x \sin(\theta/2) \\ \hat{\bm{\omega}}_y \sin(\theta/2) \\ \hat{\bm{\omega}}_z \sin(\theta/2) \end{bmatrix} \in \Reals^4 \end{equation}\]

By simply enforcing that the sum of the squares of these 4 variables equals 1 (\(q_0^2 + q_1^2 + q_2^2 + q_3^2 = 1\)), a Unit Quaternion provides a singularity-free, ultra-fast algebraic mapping of \(\SO\).

Throughout The Geometry of Motion, specifically when interacting with engines like Pinocchio or MuJoCo (as wrapped by the companion platform accompanying this textbook), all 3D rotational mechanics explicitly bypass Euler Angles and map directly into Quaternions and \(\SO\) Rotation Matrices.

Numerical Stability: A Practical Consideration

The choice between different rotation parameterizations has profound implications not just for singularities (which Gimbal Lock handles for Euler Angles), but for numerical stability during computation. This is critically important for practitioners implementing control algorithms and physics simulators. Rather than treating numerical stability as a post-hoc “patch,” it deserves integration into the design of the rotation representation itself.

Rotation Matrices: Stability Through Constraints

Rotation Matrices (\(R \in \SO\)) are numerically robust once computed correctly—multiplication is simple matrix multiplication, and the 9 entries intrinsically encode orthonormality constraints. However, maintaining this orthonormality over thousands of sequential matrix multiplications (as in iterative dynamics algorithms) requires periodic re-orthogonalization (e.g., QR factorization), adding computational cost. The advantage of matrices is that once you enforce \(R^T R = I\) (which is cheap to check), you directly access the body-frame axes \(\hat{x}_b, \hat{y}_b, \hat{z}_b\) needed for many geometric calculations. In robotics engines like MuJoCo and Pinocchio, rotation matrices are preferred for their transparency, even at the cost of occasional re-orthogonalization during long kinematic chains.

Unit Quaternions: Efficiency Meets Stability

Unit Quaternions are typically the most numerically stable choice for continuous rotations and interpolation. They require only 4 parameters, compute quaternion multiplication very efficiently, and maintain the unit-norm constraint easily (via simple normalization). Critically, quaternion interpolation (SLERP) is geometrically smooth and well-behaved, making quaternions ideal for smoothly varying trajectories. However, the double-cover property (where \(q\) and \(-q\) represent the same rotation) must be handled carefully in algorithms to avoid jumping discontinuities. For real-time simulation at high frequency (e.g., 1000 Hz golf swing dynamics), quaternions are the preferred internal representation, with rotation matrices computed on-demand when the body axes are needed.

Euler Angles: Where Singularities Propagate

Euler Angles suffer from Gimbal Lock (a singularity), but near the singularity—even when not exactly at \(90°\)—the Jacobian becomes poorly conditioned, meaning small changes in joint angles produce wildly inconsistent changes in orientation. This numerical ill-conditioning makes Euler Angles dangerous for iterative algorithms, not just at the singularity itself, but in a neighborhood around it. For these reasons, Euler Angles should be avoided entirely in computational algorithms—reserve them only for human-readable initialization and visualization.

Practical Guidance

For real-time control and simulation, the recommendation depends on the application context:

  • Continuous dynamics and long kinematic chains: Use unit quaternions internally for efficiency and numerical robustness. Convert to rotation matrices only when geometric insight (e.g., body-frame projections) is needed.
  • Frequent composition with geometric constraints: Use rotation matrices with periodic re-orthogonalization. The cost of QR decomposition is negligible compared to the computational savings of avoiding quaternion-to-matrix conversion overhead.
  • High-speed ballistic motion (e.g., golf swing): Prefer quaternions to handle rapid changes in angular velocity without singularity concerns.

To merge Translation and Rotation into a single unified control framework for physical bodies mapping the full world, we must upgrade from \(3 \times 3\) Rotation Matrices to the magnificent \(4 \times 4\) space of \(\SE\).