|
Unit quaternions and Direction Cosine matrices are two standard ways to encode three-dimensional orientation. The quaternion form is compact and avoids the singularities of Euler angles; the matrix form acts directly on vectors, exposes the geometry of the rotated basis, and interfaces naturally with rigid-body kinematics and linear algebra software. This entry derives the matrix associated with a unit quaternion, explains the relation between active and passive usage, and shows
how to move between the two representations.
This article uses the PhysicsLibrary house convention:
- right-handed orthonormal frames;
- Hamilton multiplication, so
;
- scalar-first display notation,
 |
(1) |
with vector part
 |
(2) |
- active vector rotation by a unit quaternion,
 |
(3) |
The associated active rotation matrix is denoted by , so that
 |
(4) |
The same quaternion written in scalar-last storage order
represents the same physical rotation.
Write the unit quaternion as
 |
(5) |
where is the scalar part and is the pure-vector part. From Q07, the quaternion vector-rotation formula is
 |
(6) |
This is already linear in , so it must have the form
. The three terms may be written as matrix actions:
 |
(7) |
 |
(8) |
and
![$\displaystyle 2q_w(\mathbf q\times\mathbf v)=2q_w[\mathbf q]_\times\mathbf v,$ $\displaystyle 2q_w(\mathbf q\times\mathbf v)=2q_w[\mathbf q]_\times\mathbf v,$](https://images.physicslibrary.org/cache/objects/1101/l2h/img16.png) |
(9) |
where
![$\displaystyle [\mathbf q]_\times= \begin{bmatrix} 0 & -q_z & q_y\ q_z & 0 & -q_x\ -q_y & q_x & 0 \end{bmatrix}$ $\displaystyle [\mathbf q]_\times= \begin{bmatrix} 0 & -q_z & q_y\ q_z & 0 & -q_x\ -q_y & q_x & 0 \end{bmatrix}$](https://images.physicslibrary.org/cache/objects/1101/l2h/img17.png) |
(10) |
is the skew-symmetric matrix for the cross product. Therefore,
![$\displaystyle \boxed{ R(q)= (q_w^2-\mathbf q^T\mathbf q)I_3 +2\mathbf q\mathbf q^T +2q_w[\mathbf q]_\times. }$ $\displaystyle \boxed{ R(q)= (q_w^2-\mathbf q^T\mathbf q)I_3 +2\mathbf q\mathbf q^T +2q_w[\mathbf q]_\times. }$](https://images.physicslibrary.org/cache/objects/1101/l2h/img18.png) |
(11) |
This compact matrix formula is often the cleanest way to derive properties.
Expanding equation (10) gives the familiar scalar-first component formula
 |
(12) |
If is unit, then is orthogonal with determinant , so it is a proper rotation matrix.
The columns of are the images of the basis vectors under the active rotation. If
,
, and
are the standard basis vectors, then
 |
(13) |
Figure shows this geometry for a representative quaternion.
Figure: A unit quaternion and its direction cosine matrix. The original basis vectors are the , , and axes. The columns of are the rotated basis vectors
,
, and
. The same matrix is produced by and .
|
|
Let
 |
(14) |
Then
and , so equation (11) becomes
 |
(15) |
This is exactly the matrix for a active rotation about the axis:
 |
(16) |
For a unit quaternion,
 |
(17) |
The inverse active rotation is therefore
 |
(18) |
At the matrix level this means
 |
(19) |
So quaternion conjugation corresponds to matrix transposition for unit quaternions.
Because equation (10) contains either quadratic terms in the quaternion components or the product
, replacing by leaves the matrix unchanged. Therefore,
 |
(20) |
This is the matrix version of the familiar fact that and represent the same physical orientation.
In mechanics and aerospace work, the phrase direction cosine matrix often refers to a passive coordinate transformation matrix. If
and
denote the coordinates of the same geometric vector in frames and , then the passive mapping is written
 |
(21) |
With the PhysicsLibrary frame quaternion , the associated matrix is
 |
(22) |
The frame-chain rule is therefore
 |
(23) |
which matches the quaternion chain
.
Suppose
is a proper rotation matrix. If the trace is not too close to , a convenient formula is
 |
(24) |
Once is known, the vector components follow from
 |
(25) |
These formulas are simple but become numerically fragile when is small, for example near a rotation. In numerical work one then switches to branch formulas based on whichever of , , , or is largest.
For a unit quaternion written in axis-angle form,
 |
(26) |
substituting into equation (10) yields the matrix Rodrigues formula
![$\displaystyle \boxed{R(q)=I_3\cos\theta +(1-\cos\theta)\widehat{\mathbf u}\widehat{\mathbf u}^T + [\widehat{\mathbf u}]_\times\sin\theta.}$ $\displaystyle \boxed{R(q)=I_3\cos\theta +(1-\cos\theta)\widehat{\mathbf u}\widehat{\mathbf u}^T + [\widehat{\mathbf u}]_\times\sin\theta.}$](https://images.physicslibrary.org/cache/objects/1101/l2h/img63.png) |
(27) |
Thus the quaternion-to-matrix map reproduces the standard axis-angle rotation matrix automatically.
The most common mistakes are:
- using the wrong component order when copying a formula from a source that assumes scalar-last storage;
- mixing active and passive interpretations without taking the transpose or inverse;
- assuming that the rows of the active matrix are the rotated basis vectors rather than the columns;
- forgetting that and give the same matrix;
- recovering a quaternion from a matrix using the trace formula near without using a numerically safer branch.
The next entry connects quaternions to Euler angles and shows how the familiar 3-2-1 yaw-pitch-roll formulas fit into the quaternion framework.
The matrix formula follows directly from the quaternion rotation law and the scalar-vector product rules. The active/passive distinction and frame-chain interpretation are standard in multibody dynamics, spacecraft attitude work, and inertial navigation. The compact form in equation (10) is especially useful for proofs, while the expanded component form in equation (11) is common in implementations.
This article is an original synthesis prepared for PhysicsLibrary and intended for release under CC BY-SA 4.0.
|