Module JNISpice
Package spice.basic

Class SpiceQuaternion


  • public class SpiceQuaternion
    extends Quaternion
    Class SpiceQuaternion represents and supports operations on SPICE-style quaternions.

    Let M be a rotation matrix such that for any vector V,

       M*V
    
    is the result of rotating V by theta radians in the counterclockwise direction about unit rotation axis vector A. Then the SPICE quaternions representing M are
    
       (+/-) (  cos(theta/2),
                sin(theta/2) A(1),
                sin(theta/2) A(2),
                sin(theta/2) A(3)  )
    

    Version 1.0.0 22-DEC-2009 (NJB)

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private double[] q  
    • Constructor Summary

      Constructors 
      Constructor Description
      SpiceQuaternion()
      Zero-arguments constructor: this creates a quaternion initialized with zeros.
      SpiceQuaternion​(double[] inArray)
      Create a SpiceQuaternion from a double array of length 4.The first array element is the scalar part of the quaternion; the remaining elements are the vector part.
      SpiceQuaternion​(double q0, double q1, double q2, double q3)
      Create a SpiceQuaternion from a list of four scalars.The first element of the list is the scalar part of the quaternion.
      SpiceQuaternion​(Matrix33 m)
      Create a unit SpiceQuaternion from a rotation matrix.
      SpiceQuaternion​(SpiceQuaternion q)
      Copy constructor.This creates a deep copy.
    • Method Summary

      Modifier and Type Method Description
      SpiceQuaternion add​(SpiceQuaternion q2)
      Add a second SpiceQuaternion to this instance.
      SpiceQuaternion conjugate()
      Return the conjugate of this SpiceQuaternion.
      double dist​(SpiceQuaternion q2)
      Return the distance (L2) between this quaternion and another.
      Vector3 getAngularVelocity​(SpiceQuaternion dq)
      Map this SpiceQuaternion and its derivative with respect to time to an angular velocity vector.
      double getElt​(int i)
      Return the element of this quaternion at index [i].
      double getScalar()
      Return the scalar (real) portion of this instance.
      Vector3 getVector()
      Return the vector (imaginary) portion of this instance.
      SpiceQuaternion mult​(SpiceQuaternion q2)
      Left-multiply a SpiceQuaternion by this SpiceQuaternion.
      SpiceQuaternion negate()
      Negate this SpiceQuaternion.
      double norm()
      Return the norm of this SpiceQuaternion.
      SpiceQuaternion scale​(double s)
      Scale this SpiceQuaternion.
      SpiceQuaternion sub​(SpiceQuaternion q2)
      Subtract a second SpiceQuaternion from this instance.
      double[] toArray()
      Return the contents of this quaternion in a double array.The first array element is the scalar part of the quaternion; the remaining elements are the vector part.
      Matrix33 toMatrix()
      Convert this quaternion to a matrix.If this quaternion has unit length, the output will be a rotation matrix.No checking is performed on the magnitude of the quaternion.
      java.lang.String toString()
      Convert a SpiceQuaternion to a String.This overrides Object's toString method.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • q

        private double[] q
    • Constructor Detail

      • SpiceQuaternion

        public SpiceQuaternion()
        Zero-arguments constructor: this creates a quaternion initialized with zeros.
      • SpiceQuaternion

        public SpiceQuaternion​(SpiceQuaternion q)
        Copy constructor.This creates a deep copy.
        Parameters:
        q - SpiceQuaternion
      • SpiceQuaternion

        public SpiceQuaternion​(double[] inArray)
                        throws SpiceException
        Create a SpiceQuaternion from a double array of length 4.The first array element is the scalar part of the quaternion; the remaining elements are the vector part.
        Parameters:
        inArray - double[]
        Throws:
        SpiceException - exception
      • SpiceQuaternion

        public SpiceQuaternion​(double q0,
                               double q1,
                               double q2,
                               double q3)
        Create a SpiceQuaternion from a list of four scalars.The first element of the list is the scalar part of the quaternion.
        Parameters:
        q0 - double
        q3 - double
        q1 - double
        q2 - double
      • SpiceQuaternion

        public SpiceQuaternion​(Matrix33 m)
                        throws SpiceException
        Create a unit SpiceQuaternion from a rotation matrix.
        Parameters:
        m - Matrix33
        Throws:
        SpiceException - exception
    • Method Detail

      • add

        public SpiceQuaternion add​(SpiceQuaternion q2)
        Add a second SpiceQuaternion to this instance.
        Parameters:
        q2 - SpiceQuaternion
        Returns:
        SpiceQuaternion
      • conjugate

        public SpiceQuaternion conjugate()
        Return the conjugate of this SpiceQuaternion.
        Returns:
        SpiceQuaternion
      • dist

        public double dist​(SpiceQuaternion q2)
        Return the distance (L2) between this quaternion and another.
        Parameters:
        q2 - SpiceQuaternion
        Returns:
        double
      • getAngularVelocity

        public Vector3 getAngularVelocity​(SpiceQuaternion dq)
                                   throws SpiceException
        Map this SpiceQuaternion and its derivative with respect to time to an angular velocity vector.
        Parameters:
        dq - SpiceQuaternion
        Returns:
        Vector3
        Throws:
        SpiceException - exception
      • getElt

        public double getElt​(int i)
                      throws SpiceException
        Return the element of this quaternion at index [i].
        Parameters:
        i - int
        Returns:
        double
        Throws:
        SpiceException - exception
      • getScalar

        public double getScalar()
        Return the scalar (real) portion of this instance.
        Returns:
        double
      • getVector

        public Vector3 getVector()
        Return the vector (imaginary) portion of this instance.
        Returns:
        Vector3
      • mult

        public SpiceQuaternion mult​(SpiceQuaternion q2)
                             throws SpiceException
        Left-multiply a SpiceQuaternion by this SpiceQuaternion.
           Let this instance be represented by q1. The returned
           SpiceQuaternion `qout' is the quaternion product
        
              q1 * q2
        
           Representing q(i) as the sum of scalar (real)
           part s(i) and vector (imaginary) part v(i)
           respectively,
        
              q1 = s1 + v1
              q2 = s2 + v2
        
           `qout' has scalar part s3 defined by
        
              s3 = s1 * s2 - &#60v1, v2&#62
        
           and vector part v3 defined by
        
              v3 = s1 * v2  +  s2 * v1  +  v1 x v2
        
           where the notation &lt , &gt denotes the inner
           product operator and x indicates the cross
           product operator.
           
        Parameters:
        q2 - SpiceQuaternion
        Returns:
        SpiceQuaternion
        Throws:
        SpiceException - exception
      • negate

        public SpiceQuaternion negate()
        Negate this SpiceQuaternion.
        Returns:
        SpiceQuaternion
      • norm

        public double norm()
        Return the norm of this SpiceQuaternion.
        Returns:
        double
      • scale

        public SpiceQuaternion scale​(double s)
        Scale this SpiceQuaternion.
        Parameters:
        s - double
        Returns:
        SpiceQuaternion
      • sub

        public SpiceQuaternion sub​(SpiceQuaternion q2)
        Subtract a second SpiceQuaternion from this instance.
        Parameters:
        q2 - SpiceQuaternion
        Returns:
        SpiceQuaternion
      • toArray

        public double[] toArray()
        Return the contents of this quaternion in a double array.The first array element is the scalar part of the quaternion; the remaining elements are the vector part.
        Returns:
        double[]
      • toMatrix

        public Matrix33 toMatrix()
                          throws SpiceException
        Convert this quaternion to a matrix.If this quaternion has unit length, the output will be a rotation matrix.No checking is performed on the magnitude of the quaternion.

        Associating SPICE Quaternions with Rotation Matrices

        
           Let FROM and TO be two right-handed reference frames, for
           example, an inertial frame and a spacecraft-fixed frame. Let the
           symbols
        
              V    ,   V
               FROM     TO
        
           denote, respectively, an arbitrary vector expressed relative to
           the FROM and TO frames. Let M denote the transformation matrix
           that transforms vectors from frame FROM to frame TO; then
        
              V   =  M * V
               TO         FROM
        
           where the expression on the right hand side represents left
           multiplication of the vector by the matrix.
        
           Then if the unit-length SPICE quaternion q represents M, where
        
              q = (q0, q1, q2, q3)
        
           the elements of M are derived from the elements of q as follows:
        
                +-                                                         -+
                |           2    2                                          |
                | 1 - 2*( q2 + q3 )   2*(q1*q2 - q0*q3)   2*(q1*q3 + q0*q2) |
                |                                                           |
                |                                                           |
                |                               2    2                      |
            M = | 2*(q1*q2 + q0*q3)   1 - 2*( q1 + q3 )   2*(q2*q3 - q0*q1) |
                |                                                           |
                |                                                           |
                |                                                   2    2  |
                | 2*(q1*q3 - q0*q2)   2*(q2*q3 + q0*q1)   1 - 2*( q1 + q2 ) |
                |                                                           |
                +-                                                         -+
        
           Note that substituting the elements of -q for those of q in the
           right hand side leaves each element of M unchanged; this shows
           that if a quaternion q represents a matrix M, then so does the
           quaternion -q.
           
        Returns:
        Matrix33
        Throws:
        SpiceException - exception
      • toString

        public java.lang.String toString()
        Convert a SpiceQuaternion to a String.This overrides Object's toString method.
        Overrides:
        toString in class java.lang.Object
        Returns:
        String