There are at least three popular ways to specify a rotation in 3-D.
- 3x3 rotation matrix (or 4x4 matrix in homogeneous coördinates)
- Euler angles (such as angles of roll, pitch, and yaw, often X, Y, and Z axis rotations, though there are many variations on Euler angles)
- Quaternions (specifies an axis of rotation and an angle of rotation about that axis)
The main thing to know about a quaternion is that it encodes two things in a 4-tuple: 1) an axis of rotation (a 3-D vector), and 2) an angle of rotation, measured as the counter-clockwise rotation in radians about that vector (right-hand rule). This can represent any 3-D rotation using four elements, only slightly more memory than used by Euler angles, and considerably less than the matrix representation.
The 4-tuple quaternion mixes the axis of rotation and angle in a strange way. Let's say the axis of rotation is the vector <x, y, z>
and the angle of rotation is theta
, measured as the right-hand rotation in radians about <x, y, z>
. Then the quaternion that represents that rotation is:
<cos(theta/2), x*sin(theta/2), y*sin(theta/2), z*sin(theta/2)>
That's really all there is to it, it's just a fairly compact representation of an arbitrary rotation. Quaternions have several advantages over Euler angles and matrix representations.
- More compact than matrix representations.
- Can perform rotations with fewer multiplications, and mathematically more stable.
- Can interpolate rotations component-by-component to generate intermediate states smoothly.
- No "gimbal lock" problem. (Google this.)
(Note: There are actually multiple forms of quaternion representations, but only one in ROS.)