CSPICE_M2Q calculates a unit quaternion corresponding to a
specified rotation matrix.
Given:
r the rotation matrix/matrices.
[3,3] = size(r); double = class(r)
or
[3,3,n] = size(r); double = class(r)
the call:
q = cspice_m2q(r)
returns:
q an array of unitlength SPICEstyle quaternion(s)
representing 'r'.
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
for details.
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
the quaternions
q = ( 0, a , a , a )
1 2 3
and
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)
MATLAB outputs:
r =
0.00000000000000 1.00000000000000 0
1.00000000000000 0.00000000000000 0
0 0 1.00000000000000
q = cspice_m2q( r )
MATLAB outputs:
q =
0.70710678118655
0
0
0.70710678118655
% _
% Confirm  q  = 1.
%
q' * q
MATLAB outputs:
ans =
1
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.
SPICEstyle 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.REQ
ROTATION.REQ
Mice Version 1.0.1, 09MAR2015, EDW (JPL)
Edited I/O section to conform to NAIF standard for Mice documentation.
Mice Version 1.0.0, 10JAN2006, EDW (JPL)
matrix to quaternion
