q2m_c |

Table of contents## Procedureq2m_c ( Quaternion to matrix ) void q2m_c ( ConstSpiceDouble q[4], SpiceDouble r[3][3] ) ## AbstractFind the rotation matrix corresponding to a specified unit quaternion. ## Required_ReadingROTATION ## KeywordsMATH MATRIX ROTATION ## Brief_I/OVARIABLE I/O DESCRIPTION -------- --- -------------------------------------------------- q I A unit quaternion. r O A rotation matrix corresponding to `q'. ## Detailed_Inputq is a unit-length SPICE-style quaternion representing a rotation. `q' has the property that || q || = 1 See the discussion of quaternion styles in -Particulars below. ## Detailed_Outputr is a 3 by 3 rotation matrix representing the same rotation as does `q'. See the discussion titled "Associating SPICE Quaternions with Rotation Matrices" in -Particulars below. ## ParametersNone. ## ExceptionsError free. 1) If `q' is not a unit quaternion, the output matrix `r' is the rotation matrix that is the result of converting normalized `q' to a rotation matrix. 2) If `q' is the zero quaternion, the output matrix `r' is the identity matrix. ## FilesNone. ## ParticularsIf a 4-dimensional vector `q' satisfies the equality || q || = 1 or equivalently 2 2 2 2 q(0) + q(1) + q(2) + q(3) = 1, then we can always find a unit vector `q' and a scalar `theta' such that q = ( cos(theta/2), sin(theta/2)a(1), sin(theta/2)a(2), sin(theta/2)a(3) ) We can interpret `a' and `theta' as the axis and rotation angle of a rotation in 3-space. If we restrict `theta' to the range [0, pi], then `theta' and `a' are uniquely determined, except if theta = pi. In this special case, `a' and -a are both valid rotation axes. Every rotation is represented by a unique orthogonal matrix; this routine returns that unique rotation matrix corresponding to `q'. The CSPICE routine m2q_c is a one-sided inverse of this routine: given any rotation matrix `r', the calls m2q_c ( r, q ) ## Examples1) A case amenable to checking by hand calculation: To convert the rotation matrix +- -+ | 0 1 0 | | | r = | -1 0 0 | | | | 0 0 1 | +- -+ also represented as [ pi/2 ] 3 to a quaternion, we can use the code fragment rotate_c ( halfpi_c(), 3, r ); m2q_c ( r, q ); m2q_c will return `q' as ( sqrt(2)/2, 0, 0, -sqrt(2)/2 ) Why? Well, `r' is a reference frame transformation that rotates vectors by -pi/2 radians about the axis vector a = ( 0, 0, 1 ) Equivalently, `r' rotates vectors by pi/2 radians in the counterclockwise sense about the axis vector -a = ( 0, 0, -1 ) so our definition of `q', h = theta/2 q = ( cos(h), sin(h)a , sin(h)a , sin(h)a ) 1 2 3 implies that in this case, q = ( cos(pi/4), 0, 0, -sin(pi/4) ) = ( sqrt(2)/2, 0, 0, -sqrt(2)/2 ) 2) Finding a set of Euler angles that represent a rotation specified by a quaternion: Suppose our rotation `r' is represented by the quaternion `q'. To find angles `tau', `alpha', `delta' such that r = [ tau ] [ pi/2 - delta ] [ alpha ] 3 2 3 we can use the code fragment ## RestrictionsNone. ## Literature_ReferencesNone. ## Author_and_InstitutionN.J. Bachman (JPL) J. Diaz del Rio (ODC Space) W.L. Taber (JPL) E.D. Wright (JPL) ## Version-CSPICE Version 1.3.3, 10-AUG-2021 (JDR) Edited the header to comply with NAIF standard. Moved ROTATIONS required reading from -Literature_References to -Required_Reading section. Updated entry #1 and added entry #2 to -Exceptions section. -CSPICE Version 1.3.2, 27-FEB-2008 (NJB) Updated header; added information about SPICE quaternion conventions. Made miscellaneous edits throughout header. -CSPICE Version 1.3.1, 06-FEB-2003 (EDW) Corrected typo error in -Examples section. -CSPICE Version 1.3.0, 24-JUL-2001 (NJB) Changed prototype: input q is now type (ConstSpiceDouble [4]). Implemented interface macro for casting input q to const. -CSPICE Version 1.2.0, 08-FEB-1998 (NJB) Removed local variables used for temporary capture of outputs. Removed tracing calls, since the underlying Fortran routine is error-free. -CSPICE Version 1.0.0, 25-OCT-1997 (NJB) (WLT) Based on SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) ## Index_Entriesquaternion to matrix |

Fri Dec 31 18:41:11 2021