CSPICE_M2Q calculates a unit quaternion corresponding to a
specified rotation matrix.
r the rotation matrix/matrices.
[3,3] = size(r); double = class(r)
[3,3,n] = size(r); double = class(r)
q = cspice_m2q(r)
q an array of unit-length SPICE-style quaternion(s)
If [3,3] = size(r) then [4,1] = size(q)
If [3,3,n] = size(r) then [4,n] = size(q)
double = class(q)
Note that multiple styles of quaternions are in use.
This routine returns a quaternion that conforms to
the SPICE convention. See the Particulars section
If 'r' rotates vectors in the counterclockwise sense by
an angle of 'theta' radians about a unit vector 'a', where
0 < theta < pi
then letting h = theta/2,
q = ( cos(h), sin(h)a , sin(h)a , sin(h)a ).
1 2 3
The restriction that 'theta' must be in the range [0, pi]
determines the output quaternion 'q' uniquely
except when theta = pi; in this special case, both of
q = ( 0, a , a , a )
1 2 3
q = ( 0, -a , -a , -a )
1 2 3
are possible outputs.
'q' returns with the same vectorization measure, N,
as 'r' .
Any numerical results shown for this example may differ between
platforms as the results depend on the SPICE kernels used as input
and the machine specific arithmetic implementation.
% Create a rotation matrix of 90 degrees about the Z axis.
r = cspice_rotate( cspice_halfpi, 3)
0.00000000000000 1.00000000000000 0
-1.00000000000000 0.00000000000000 0
0 0 1.00000000000000
q = cspice_m2q( r )
% Confirm || q || = 1.
q' * q
About SPICE quaternions
There are (at least) two popular "styles" of quaternions; these
differ in the layout of the quaternion elements, the definition
of the multiplication operation, and the mapping between the set
of unit quaternions and corresponding rotation matrices.
SPICE-style quaternions have the scalar part in the first
component and the vector part in the subsequent components. The
SPICE convention, along with the multiplication rules for SPICE
quaternions, are those used by William Rowan Hamilton, the
inventor of quaternions.
Another common quaternion style places the scalar component
last. This style is often used in engineering applications.
For important details concerning this module's function, please refer to
the CSPICE routine m2q_c.
-Mice Version 1.0.1, 09-MAR-2015, EDW (JPL)
Edited I/O section to conform to NAIF standard for Mice documentation.
-Mice Version 1.0.0, 10-JAN-2006, EDW (JPL)
matrix to quaternion