What Quaternions Are
Quaternions are an extension of complex numbers that provide a compact way to represent 3D rotations. They consist of four components: one real part and three imaginary parts, often denoted as q = w + xi + yj + zk. In the context of 2D quaternion rotation, we focus on quaternions representing axis-angle rotations in 3D space, which can be projected onto a 2D plane.
The primary advantage of using quaternions over traditional Euler angles is their ability to avoid gimbal lock and provide smooth interpolation between orientations through spherical linear interpolation (SLERP).
Why Quaternions Rotate Vectors
Quaternion rotation leverages the Hamilton product, a non-commutative operation that allows for efficient computation of rotations. The key formula is q·v·q⁻¹, where v is a 3D vector represented as a quaternion with zero real part (i.e., w = 0), and q represents an axis-angle rotation quaternion. This process effectively rotates the vector in 3D space while maintaining computational simplicity.
In 2D, this operation can be visualized by orthographically projecting 3D points onto a plane, allowing us to see the effects of quaternion rotations directly on our screen.
Avoiding Gimbal Lock
Gimbal lock occurs when two rotational axes align, causing a loss of one degree of freedom. Euler angles are particularly susceptible to this issue, which can lead to singularities and unpredictable behavior in certain orientations. Quaternions, on the other hand, represent rotations as a single axis-angle pair, avoiding these issues entirely.
The Euler-angle gimbal-lock proof provided in the simulation demonstrates how quaternions maintain stability across all possible orientations.
SLERP Interpolation
Spherical linear interpolation (SLERP) is a method for smoothly interpolating between two quaternions representing different rotations. This technique ensures that the path taken during interpolation lies on the shortest arc of the 3-sphere, providing visually smooth and continuous transitions.
The SLERP mode in the simulation allows you to explore this concept by specifying two independent axis-angle quaternions and a parameter t that controls the interpolation progress.
Frequently asked questions
What is gimbal lock, and why does it matter?
Gimbal lock occurs when two rotational axes align, causing a loss of one degree of freedom. This can lead to singularities in Euler angles, making rotations unpredictable. Quaternions avoid this issue by representing rotations as axis-angle pairs.
How does SLERP ensure smooth interpolation?
SLERP interpolates between two quaternions along the shortest path on a 3-sphere, ensuring that the transition is both visually smooth and continuous without any abrupt changes in orientation.
Can quaternions be used for 2D rotations as well?
While primarily designed for 3D rotations, quaternions can indeed be projected onto a 2D plane to demonstrate their properties. This projection allows us to visualize the effects of quaternion rotations in a simplified context.
What is the Hamilton product, and how does it relate to quaternion rotations?
The Hamilton product is a non-commutative operation that defines how quaternions multiply with each other. It is crucial for performing quaternion rotations as q·v·q⁻¹, where v is a vector represented as a quaternion.
Try it live
Everything above runs in your browser — open 2D Quaternion Rotation and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open 2D Quaternion Rotation simulation