Index of Functions: A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X 
Index Page
m2eul

Table of contents
Procedure
Abstract
Required_Reading
Keywords
Declarations
Brief_I/O
Detailed_Input
Detailed_Output
Parameters
Exceptions
Files
Particulars
Examples
Restrictions
Literature_References
Author_and_Institution
Version

Procedure

     M2EUL ( Matrix to Euler angles )

     SUBROUTINE M2EUL (  R,  AXIS3,   AXIS2,   AXIS1,
    .                        ANGLE3,  ANGLE2,  ANGLE1  )

Abstract

     Factor a rotation matrix as a product of three rotations about
     specified coordinate axes.

Required_Reading

     ROTATION

Keywords

     ANGLE
     MATRIX
     ROTATION
     TRANSFORMATION

Declarations

     IMPLICIT NONE

     DOUBLE PRECISION      R      ( 3, 3 )

     INTEGER               AXIS3
     INTEGER               AXIS2
     INTEGER               AXIS1

     DOUBLE PRECISION      ANGLE3
     DOUBLE PRECISION      ANGLE2
     DOUBLE PRECISION      ANGLE1

Brief_I/O

     VARIABLE  I/O  DESCRIPTION
     --------  ---  --------------------------------------------------
     R          I   A rotation matrix to be factored.
     AXIS3,
     AXIS2,
     AXIS1      I   Numbers of third, second, and first rotation axes.
     ANGLE3,
     ANGLE2,
     ANGLE1     O   Third, second, and first Euler angles, in radians.

Detailed_Input

     R        is a 3x3 rotation matrix that is to be factored as
              a product of three rotations about a specified
              coordinate axes. The angles of these rotations are
              called "Euler angles."

     AXIS3,
     AXIS2,
     AXIS1    are the indices of the rotation axes of the
              "factor" rotations, whose product is R. R is
              factored as

                 R = [ ANGLE3 ]      [ ANGLE2 ]      [ ANGLE1 ]
                               AXIS3           AXIS2           AXIS1

              The axis numbers must belong to the set {1, 2, 3}.
              The second axis number MUST differ from the first
              and third axis numbers.

              See the $Particulars section below for details
              concerning this notation.

Detailed_Output

     ANGLE3,
     ANGLE2,
     ANGLE1   are the Euler angles corresponding to the matrix
              R and the axes specified by AXIS3, AXIS2, and
              AXIS1. These angles satisfy the equality

                 R = [ ANGLE3 ]      [ ANGLE2 ]      [ ANGLE1 ]
                               AXIS3           AXIS2           AXIS1


              See the $Particulars section below for details
              concerning this notation.

              The range of ANGLE3 and ANGLE1 is (-pi, pi].

              The range of ANGLE2 depends on the exact set of
              axes used for the factorization. For
              factorizations in which the first and third axes
              are the same,

                 R = [r]  [s]  [t] ,
                        a    b    a

              the range of ANGLE2 is [0, pi].

              For factorizations in which the first and third
              axes are different,

                 R = [r]  [s]  [t] ,
                        a    b    c

              the range of ANGLE2 is [-pi/2, pi/2].

              For rotations such that ANGLE3 and ANGLE1 are not
              uniquely determined, ANGLE3 will always be set to
              zero; ANGLE1 is then uniquely determined.

Parameters

     None.

Exceptions

     1)  If any of AXIS3, AXIS2, or AXIS1 do not have values in

            { 1, 2, 3 }

         the error SPICE(BADAXISNUMBERS) is signaled.

     2)  If AXIS2 is equal to AXIS3 or AXIS1, the error
         SPICE(BADAXISNUMBERS) is signaled. An arbitrary rotation
         matrix cannot be expressed using a sequence of Euler angles
         unless the second rotation axis differs from the other two.

     3)  If the input matrix R is not a rotation matrix, the error
         SPICE(NOTAROTATION) is signaled.

     4)  If ANGLE3 and ANGLE1 are not uniquely determined, ANGLE3
         is set to zero, and ANGLE1 is determined.

Files

     None.

Particulars

     A word about notation: the symbol

        [ x ]
             i

     indicates a coordinate system rotation of x radians about the
     ith coordinate axis. To be specific, the symbol

        [ x ]
             1

     indicates a coordinate system rotation of x radians about the
     first, or x-, axis; the corresponding matrix is

        .-                    -.
        |  1      0       0    |
        |                      |
        |  0    cos(x)  sin(x) |
        |                      |
        |  0   -sin(x)  cos(x) |
        `-                    -'

     Remember, this is a COORDINATE SYSTEM rotation by x radians; this
     matrix, when applied to a vector, rotates the vector by -x
     radians, not x radians. Applying the matrix to a vector yields
     the vector's representation relative to the rotated coordinate
     system.

     The analogous rotation about the second, or y-, axis is
     represented by

        [ x ]
             2

     which symbolizes the matrix

        .-                    -.
        | cos(x)   0   -sin(x) |
        |                      |
        |  0       1      0    |
        |                      |
        | sin(x)   0    cos(x) |
        `-                    -'

     and the analogous rotation about the third, or z-, axis is
     represented by

        [ x ]
             3

     which symbolizes the matrix

        .-                    -.
        |  cos(x)  sin(x)   0  |
        |                      |
        | -sin(x)  cos(x)   0  |
        |                      |
        |  0        0       1  |
        `-                    -'


     The input matrix is assumed to be the product of three
     rotation matrices, each one of the form

        .-                    -.
        |  1      0       0    |
        |                      |
        |  0    cos(r)  sin(r) |     (rotation of r radians about the
        |                      |      x-axis),
        |  0   -sin(r)  cos(r) |
        `-                    -'


        .-                    -.
        | cos(s)   0   -sin(s) |
        |                      |
        |  0       1      0    |     (rotation of s radians about the
        |                      |      y-axis),
        | sin(s)   0    cos(s) |
        `-                    -'

     or

        .-                    -.
        |  cos(t)  sin(t)   0  |
        |                      |
        | -sin(t)  cos(t)   0  |     (rotation of t radians about the
        |                      |      z-axis),
        |  0        0       1  |
        `-                    -'

     where the second rotation axis is not equal to the first or
     third. Any rotation matrix can be factored as a sequence of
     three such rotations, provided that this last criterion is met.

     This routine is related to the SPICELIB routine EUL2M, which
     produces a rotation matrix, given a sequence of Euler angles.
     This routine is a `right inverse' of EUL2M:  the sequence of
     calls

        CALL M2EUL ( R,  AXIS3,   AXIS2,   AXIS1,
       .                 ANGLE3,  ANGLE2,  ANGLE1     )

        CALL EUL2M (     ANGLE3,  ANGLE2,  ANGLE1,
       .                 AXIS3,   AXIS2,   AXIS1,   R )

     preserves R, except for round-off error.


     On the other hand, the sequence of calls

        CALL EUL2M (     ANGLE3,  ANGLE2,  ANGLE1,
       .                 AXIS3,   AXIS2,   AXIS1,   R )

        CALL M2EUL ( R,  AXIS3,   AXIS2,   AXIS1,
       .                 ANGLE3,  ANGLE2,  ANGLE1     )


     preserve ANGLE3, ANGLE2, and ANGLE1 only if these angles start
     out in the ranges that M2EUL's outputs are restricted to.

Examples

     The numerical results shown for these examples may differ across
     platforms. The results depend on the SPICE kernels used as
     input, the compiler and supporting libraries, and the machine
     specific arithmetic implementation.

     1) Conversion of instrument pointing from a matrix representation
        to Euler angles:

        Suppose we want to find camera pointing in alpha, delta, and
        kappa, given the inertial-to-camera coordinate transformation


        .-                                                         -.
        |  0.491273796781358  0.508726203218642  0.706999085398824  |
        |                                                           |
        | -0.508726203218642 -0.491273796781358  0.706999085398824  |
        |                                                           |
        |  0.706999085398824 -0.706999085398824  0.017452406437284  |
        `-                                                         -'


        Find angles alpha, delta, kappa such that

           TICAM  =  [ kappa ]  [ pi/2 - delta ]  [ pi/2 + alpha ] .
                              3                 1                 3

        Example code begins here.


              PROGRAM M2EUL_EX1
              IMPLICIT NONE

        C
        C     SPICELIB functions
        C
              DOUBLE PRECISION      DPR
              DOUBLE PRECISION      HALFPI
              DOUBLE PRECISION      TWOPI

        C
        C     Local variables
        C
              DOUBLE PRECISION      ALPHA
              DOUBLE PRECISION      ANG1
              DOUBLE PRECISION      ANG2
              DOUBLE PRECISION      DELTA
              DOUBLE PRECISION      KAPPA
              DOUBLE PRECISION      TICAM  ( 3, 3 )


              DATA TICAM /  0.491273796781358D0,
             .             -0.508726203218642D0,
             .              0.706999085398824D0,
             .              0.508726203218642D0,
             .             -0.491273796781358D0,
             .             -0.706999085398824D0,
             .              0.706999085398824D0,
             .              0.706999085398824D0,
             .              0.017452406437284D0  /


              CALL M2EUL ( TICAM, 3, 1, 3, KAPPA, ANG2, ANG1 )

              DELTA = HALFPI() - ANG2
              ALPHA = ANG1     - HALFPI()

              IF ( KAPPA .LT. 0.D0 ) THEN
                 KAPPA = KAPPA + TWOPI()
              END IF

              IF ( ALPHA .LT. 0.D0 ) THEN
                 ALPHA = ALPHA + TWOPI()
              END IF

              WRITE (*,'(A,F24.14)') 'Alpha (deg): ', DPR() * ALPHA
              WRITE (*,'(A,F24.14)') 'Delta (deg): ', DPR() * DELTA
              WRITE (*,'(A,F24.14)') 'Kappa (deg): ', DPR() * KAPPA

              END


        When this program was executed on a Mac/Intel/gfortran/64-bit
        platform, the output was:


        Alpha (deg):       315.00000000000000
        Delta (deg):         1.00000000000003
        Kappa (deg):        45.00000000000000


     2) Conversion of instrument pointing angles from a non-J2000,
        not necessarily inertial frame to J2000-relative RA, Dec,
        and Twist.

        Suppose that we have orientation for the CASSINI Narrow Angle
        Camera (NAC) frame expressed as

           [ gamma ]  [ beta ]  [ alpha ]
                    1         2          3

        with respect to the CASSINI spacecraft frame.

        We want to express that orientation with respect to the J2000
        frame as the sequence of rotations

           [ twist ]  [ dec ]  [ ra ] .
                    3        1       3

        Use the meta-kernel shown below to load the required SPICE
        kernels.


           KPL/MK

           File name: m2eul_ex2.tm

           This meta-kernel is intended to support operation of SPICE
           example programs. The kernels shown here should not be
           assumed to contain adequate or correct versions of data
           required by SPICE-based user applications.

           In order for an application to use this meta-kernel, the
           kernels referenced here must be present in the user's
           current working directory.

           The names and contents of the kernels referenced
           by this meta-kernel are as follows:

              File name                      Contents
              ---------                      --------
              naif0010.tls                   Leapseconds
              cas00145.tsc                   Cassini SCLK
              cas_v40.tf                     Cassini frames
              08052_08057ra.bc               Orientation for Cassini

           \begindata

              KERNELS_TO_LOAD = ( 'naif0010.tls'
                                  'cas00145.tsc'
                                  'cas_v40.tf'
                                  '08052_08057ra.bc')

           \begintext

           End of meta-kernel


        Example code begins here.


              PROGRAM M2EUL_EX2
              IMPLICIT NONE

        C
        C     SPICELIB functions
        C
              DOUBLE PRECISION      DPR
              DOUBLE PRECISION      HALFPI
              DOUBLE PRECISION      RPD
              DOUBLE PRECISION      TWOPI

        C
        C     Local parameters
        C
              CHARACTER*(*)         META
              PARAMETER           ( META   =  'm2eul_ex2.tm' )

              DOUBLE PRECISION      ALPHA
              PARAMETER           ( ALPHA =  89.9148D0   )

              DOUBLE PRECISION      BETA
              PARAMETER           ( BETA  = -0.03300D0   )

              DOUBLE PRECISION      GAMMA
              PARAMETER           ( GAMMA = -90.009796D0 )

        C
        C     Local variables
        C
              DOUBLE PRECISION      RA
              DOUBLE PRECISION      ANG1
              DOUBLE PRECISION      ANG2
              DOUBLE PRECISION      DEC
              DOUBLE PRECISION      ET
              DOUBLE PRECISION      INST2J ( 3, 3 )
              DOUBLE PRECISION      INST2S ( 3, 3 )
              DOUBLE PRECISION      S2J    ( 3, 3 )
              DOUBLE PRECISION      TWIST

        C
        C     Load the kernels.
        C
              CALL FURNSH ( META )

        C
        C     First, we use subroutine EUL2M to form the
        C     transformation from instrument coordinates to
        C     CASSINI spacecraft frame.
        C
              CALL EUL2M ( GAMMA * RPD(), BETA * RPD(), ALPHA * RPD(),
             .             1,             2,            3,    INST2S )

        C
        C     Now we compute the transformation from CASSINI
        C     spacecraft frame to J2000, at a given time.
        C
              CALL STR2ET ( '2008 Feb 25', ET )
              CALL PXFORM ( 'CASSINI_SC_COORD', 'J2000', ET, S2J )

        C
        C     Next, we form the transformation from instrument
        C     coordinates to J2000 frame.
        C
              CALL MXM ( S2J, INST2S, INST2J )

        C
        C     Finally, we express INST2J using the desired Euler
        C     angles.
        C
              CALL M2EUL ( INST2J, 3, 1, 3, TWIST, ANG1, ANG2 )

              RA   =  ANG2 - HALFPI()
              DEC  =  HALFPI() - ANG1

        C
        C     If we wish to make sure that RA, DEC, and TWIST are in
        C     the ranges [0, 2pi), [-pi/2, pi/2], and [0, 2pi)
        C     respectively, we may add the code
        C
              IF ( RA .LT. 0.D0 ) THEN
                 RA = RA + TWOPI()
              END IF

              IF ( TWIST .LT. 0.D0 ) THEN
                 TWIST = TWIST + TWOPI()
              END IF

        C
        C     Now RA, DEC, and TWIST express the instrument pointing
        C     as RA, Dec, and Twist, relative to the J2000 system.
        C
              WRITE (*,'(A,F24.14)') 'RA    (deg): ', DPR() * RA
              WRITE (*,'(A,F24.14)') 'Dec   (deg): ', DPR() * DEC
              WRITE (*,'(A,F24.14)') 'Twist (deg): ', DPR() * TWIST

              END


        When this program was executed on a Mac/Intel/gfortran/64-bit
        platform, the output was:


        RA    (deg):        83.77802387778848
        Dec   (deg):       -14.92925498590898
        Twist (deg):       294.55732942050986


        Note:  more than one definition of RA, Dec, and Twist is
        extant. Before using this example in an application, check
        that the definition given here is consistent with that used
        in your application.

Restrictions

     None.

Literature_References

     None.

Author_and_Institution

     N.J. Bachman       (JPL)
     J. Diaz del Rio    (ODC Space)
     W.L. Taber         (JPL)

Version

    SPICELIB Version 1.3.0, 06-JUL-2021 (JDR)

        Added IMPLICIT NONE statement.

        Edited the header to comply with NAIF standard. Removed
        unnecessary entries from $Revisions section.

        Added complete code examples from existing fragments.

        Removed erroneous comments about behavior of ATAN2.

    SPICELIB Version 1.2.1, 21-DEC-2006 (NJB)

        Error corrected in header example: input matrix
        previously did not match shown outputs. Offending
        example now includes complete program.

    SPICELIB Version 1.2.0, 15-OCT-2005 (NJB)

        Updated to remove non-standard use of duplicate arguments
        in MXM and MTXM calls. A short error message cited in
        the $Exceptions section of the header failed to match
        the actual short message used; this has been corrected.

    SPICELIB Version 1.1.2, 13-OCT-2004 (NJB)

        Fixed header typo.

    SPICELIB Version 1.1.1, 10-MAR-1992 (WLT)

        Comment section for permuted index source lines was added
        following the header.

    SPICELIB Version 1.1.0, 02-NOV-1990 (NJB)

        Header upgraded to describe notation in more detail. Argument
        names were changed to describe the use of the arguments more
        accurately. No change in functionality was made; the operation
        of the routine is identical to that of the previous version.

    SPICELIB Version 1.0.0, 03-SEP-1990 (NJB)
Fri Dec 31 18:36:33 2021