JNISpice
version 2.0.0

spice.basic
Class SpiceQuaternion

java.lang.Object
  extended by spice.basic.Quaternion
      extended by spice.basic.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)


Constructor Summary
SpiceQuaternion()
          Zero-arguments constructor: this creates a quaternion initialized with zeros.
SpiceQuaternion(double[] inArray)
          Create a SpiceQuaternion from a double array of length 4.
SpiceQuaternion(double q0, double q1, double q2, double q3)
          Create a SpiceQuaternion from a list of four scalars.
SpiceQuaternion(Matrix33 m)
          Create a unit SpiceQuaternion from a rotation matrix.
SpiceQuaternion(SpiceQuaternion q)
          Copy constructor.
 
Method Summary
 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.
 Matrix33 toMatrix()
          Convert this quaternion to a matrix.
 java.lang.String toString()
          Convert a SpiceQuaternion to a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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.


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.

Throws:
SpiceException

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.


SpiceQuaternion

public SpiceQuaternion(Matrix33 m)
                throws SpiceException
Create a unit SpiceQuaternion from a rotation matrix.

Throws:
SpiceException
Method Detail

add

public SpiceQuaternion add(SpiceQuaternion q2)
Add a second SpiceQuaternion to this instance.


conjugate

public SpiceQuaternion conjugate()
Return the conjugate of this SpiceQuaternion.


dist

public double dist(SpiceQuaternion q2)
Return the distance (L2) between this quaternion and another.


getAngularVelocity

public Vector3 getAngularVelocity(SpiceQuaternion dq)
                           throws SpiceException
Map this SpiceQuaternion and its derivative with respect to time to an angular velocity vector.

Throws:
SpiceException

getElt

public double getElt(int i)
              throws SpiceException
Return the element of this quaternion at index [i].

Throws:
SpiceException

getScalar

public double getScalar()
Return the scalar (real) portion of this instance.


getVector

public Vector3 getVector()
Return the vector (imaginary) portion of this instance.


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 - <v1, v2>

   and vector part v3 defined by

      v3 = s1 * v2  +  s2 * v1  +  v1 x v2

   where the notation < , > denotes the inner
   product operator and x indicates the cross
   product operator.
   

Throws:
SpiceException

negate

public SpiceQuaternion negate()
Negate this SpiceQuaternion.


norm

public double norm()
Return the norm of this SpiceQuaternion.


scale

public SpiceQuaternion scale(double s)
Scale this SpiceQuaternion.


sub

public SpiceQuaternion sub(SpiceQuaternion q2)
Subtract a second SpiceQuaternion from this instance.


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.


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.
   

Throws:
SpiceException

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

JNISpice
version 2.0.0

JNISpice Alpha Test Version 2.0.0 28-JAN-2017 (NJB)