jautil.geometry
Class Quaternion

java.lang.Object
  extended by jautil.geometry.Quaternion

public class Quaternion
extends java.lang.Object

Quaternion class with various standard operations, including conversion to/from rotation matrices and Euler angles.


Field Summary
static double DEGS_TO_RADS
           
static float GS_EPSILON
           
static Quaternion IDENTITY
           
static double RADS_TO_DEGS
           
static Quaternion ZERO
           
 
Constructor Summary
Quaternion()
          Constructs a new Quaternion with default values: w=1, xyz=0.
Quaternion(float[] xyzw)
          Constructs a new Quaternion from the given component values (with w last).
Quaternion(float roll, float pitch, float yaw)
          Construts a quaternion from the given "Euler" angles.
Quaternion(float ww, float xx, float yy, float zz)
          Constructs a new Quaternion from the given component values.
Quaternion(JAInputStream jins)
          Constructs a new Quaternion by reading the values x,y,z,w (in that order -- NB w comes last!) from the given input stream.
Quaternion(Quaternion q)
          Constructs a copy of the given quaternion.
 
Method Summary
 Quaternion add(Quaternion q)
          Returns a new Quaternion representing this + q.
 Quaternion exp()
          Return a new Quaternion representing the exponential of this one.
 void extractRotX(Quaternion qx)
          Decomposes this quaternion into qx.qyz, where qx and qyz represent rotations about, respectively, the x-axis and some axis in the yz-plane, setting the given qx to be the first of the two factors.
 void fromAngleAxis(float angle, float axisX, float axisY, float axisZ)
          Sets this Quaternion to represent a rotation by the given angle about the axis with the given components -- where the axis length should be 1.
 void fromAxisRotations(float roll, float pitch, float yaw)
          Set this Quaternion from the given "Euler" angle values (in degrees), that is, sequence of rotations about the axes.
 float innerProd(Quaternion q)
          Returns the inner product of this Quaternion with the given one.
 Quaternion inverse()
          Returns a new Quaternion containing the multiplicative inverse of this one.
 Quaternion inverseUnit()
          Returns a new Quaternion containing the multiplicative inverse of this one, assuming this one has unit length.
 void invertUnit()
          Inverts this Quaternion, assuming it has unit length.
 Quaternion log()
          Return a new Quaternion representing the logarithm of this one.
 Quaternion negate()
          Returns a new Quaternion representing the negation of this one.
 void negateEq()
          Negates this quaternion.
 void negateXEq()
          Negates the x component of this quaternion.
 void normalize()
          Normalizes this quaternion -- i.e.
 void postDivideUnitEq(Quaternion q)
           
 Quaternion postMultiply(Quaternion q)
          Returns a new Quaternion representing this * q.
 void postMultiplyEq(Quaternion q)
          Post-multiply this Quaternion by the given one, that is, this := this * q (Grassman product, as defined below).
 void preMultiplyEq(Quaternion q)
          Pre-multiply this Quaternion by the given one, that is, this := q * this (Grassman product -- as defined for postMultiplyEq() above).
 void save(JAOutputStream jouts)
          Writes this quaternion to the given stream.
 Quaternion scalarMultiply(float f)
          Returns a new Quaternion representing this * f (scalar f).
 void scalarMultiplyEq(float f)
          Multiplies this quaternion by the given scalar (that is, this := this * f).
 void scale(float T)
          Scales this quaternion by the specified fraction -- achieved using SLERP (spherical linear interpolation) with the identity quaternion (representing the null rotation).
 void scaleXRotationAngle(float scale)
          Scales the angle of rotation in this quaternion by the given amount, assuming this quaternion represents a rotation about the X-axis, that is, this = (cos A/2, sin A/2, 0, 0).
 void set(float[] xyzw)
          Resets this Quaternion from the given component values (in which w comes last).
 void set(float ww, float xx, float yy, float zz)
          Resets this Quaternion from the given component values.
 void set(Quaternion q)
          Resets this Quaternion as a copy of the given one, q.
 void setFromRotationMatrix3x3(float[] m)
          Sets this quaternion from the given 3 x 3 rotation matrix (which is in column-major order).
 void setInverseUnit(Quaternion q)
          Sets this Quaternion to be the inverse of the given one, q.
static void slerp(Quaternion qq, Quaternion qa, Quaternion qb, float T)
          Sets quaternion qq to be the SLERP (spherical linear interpolation), with fraction T, between the two (unit) quaternions qa, qb.
 Quaternion subtract(Quaternion q)
          Returns a new Quaternion representing this - q.
 void toAxisRotations(float[] result)
          Computes the "Euler" angles, that is, the sequence of rotations about the axes (roll [about X], pitch [about Y], yaw [about Z]), corresponding to this Quaternion -- with result values in degrees.
 void toFloats(float[] xyzw)
          Sets the given float-array to the components of this quaternion -- in x,y,z,w order.
 void toRotationMatrix3x3(float[] m)
          Sets the given 3x3 rotation matrix from this Quaternion.
 void toRotationMatrix4x4(float[] m)
          Sets the 3x3 rotation sub-matrix of the given 4x4 tranformation matrix from this Quaternion.
 java.lang.String toString()
           
 float w()
          Returns w component of this Quaternion.
 float x()
          Returns x component of this Quaternion.
 float y()
          Returns y component of this Quaternion.
 float z()
          Returns z component of this Quaternion.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEGS_TO_RADS

public static double DEGS_TO_RADS

RADS_TO_DEGS

public static double RADS_TO_DEGS

ZERO

public static Quaternion ZERO

IDENTITY

public static Quaternion IDENTITY

GS_EPSILON

public static float GS_EPSILON
Constructor Detail

Quaternion

public Quaternion(JAInputStream jins)
           throws java.io.IOException
Constructs a new Quaternion by reading the values x,y,z,w (in that order -- NB w comes last!) from the given input stream.

Throws:
java.io.IOException

Quaternion

public Quaternion(float ww,
                  float xx,
                  float yy,
                  float zz)
Constructs a new Quaternion from the given component values.


Quaternion

public Quaternion()
Constructs a new Quaternion with default values: w=1, xyz=0.


Quaternion

public Quaternion(float[] xyzw)
Constructs a new Quaternion from the given component values (with w last).


Quaternion

public Quaternion(Quaternion q)
Constructs a copy of the given quaternion.


Quaternion

public Quaternion(float roll,
                  float pitch,
                  float yaw)
Construts a quaternion from the given "Euler" angles.

Method Detail

save

public void save(JAOutputStream jouts)
          throws java.io.IOException
Writes this quaternion to the given stream.

Throws:
java.io.IOException

w

public float w()
Returns w component of this Quaternion.


x

public float x()
Returns x component of this Quaternion.


y

public float y()
Returns y component of this Quaternion.


z

public float z()
Returns z component of this Quaternion.


set

public void set(Quaternion q)
Resets this Quaternion as a copy of the given one, q.


set

public void set(float ww,
                float xx,
                float yy,
                float zz)
Resets this Quaternion from the given component values.


set

public void set(float[] xyzw)
Resets this Quaternion from the given component values (in which w comes last).


setFromRotationMatrix3x3

public void setFromRotationMatrix3x3(float[] m)
Sets this quaternion from the given 3 x 3 rotation matrix (which is in column-major order).


toFloats

public void toFloats(float[] xyzw)
Sets the given float-array to the components of this quaternion -- in x,y,z,w order.


toRotationMatrix4x4

public void toRotationMatrix4x4(float[] m)
Sets the 3x3 rotation sub-matrix of the given 4x4 tranformation matrix from this Quaternion.


toRotationMatrix3x3

public void toRotationMatrix3x3(float[] m)
Sets the given 3x3 rotation matrix from this Quaternion.


fromAngleAxis

public void fromAngleAxis(float angle,
                          float axisX,
                          float axisY,
                          float axisZ)
Sets this Quaternion to represent a rotation by the given angle about the axis with the given components -- where the axis length should be 1. [## CURENTLY UNUSED ##]


add

public Quaternion add(Quaternion q)
Returns a new Quaternion representing this + q. [## CURRENTLY UNUSED ##]


subtract

public Quaternion subtract(Quaternion q)
Returns a new Quaternion representing this - q. [## CURRENTLY UNUSED ##]


postMultiply

public Quaternion postMultiply(Quaternion q)
Returns a new Quaternion representing this * q. [## CURRENTLY UNUSED ##]


negateEq

public void negateEq()
Negates this quaternion.


negateXEq

public void negateXEq()
Negates the x component of this quaternion.


postMultiplyEq

public void postMultiplyEq(Quaternion q)
Post-multiply this Quaternion by the given one, that is, this := this * q (Grassman product, as defined below). The Grassman product is defined by: * = where a, b are scalars, U, V are 3-vectors, . denotes inner product, and x denotes cross-product. In general, this product is _not_ commutative.


preMultiplyEq

public void preMultiplyEq(Quaternion q)
Pre-multiply this Quaternion by the given one, that is, this := q * this (Grassman product -- as defined for postMultiplyEq() above).


postDivideUnitEq

public void postDivideUnitEq(Quaternion q)

scalarMultiply

public Quaternion scalarMultiply(float f)
Returns a new Quaternion representing this * f (scalar f). [## CURRENTLY UNUSED ##]


scalarMultiplyEq

public void scalarMultiplyEq(float f)
Multiplies this quaternion by the given scalar (that is, this := this * f). [## CURRENTLY UNUSED ##]


negate

public Quaternion negate()
Returns a new Quaternion representing the negation of this one. [## CURRENTLY UNUSED ##]


innerProd

public float innerProd(Quaternion q)
Returns the inner product of this Quaternion with the given one.


inverse

public Quaternion inverse()
Returns a new Quaternion containing the multiplicative inverse of this one. [## CURRENTLY UNUSED ##]


inverseUnit

public Quaternion inverseUnit()
Returns a new Quaternion containing the multiplicative inverse of this one, assuming this one has unit length. [## CURRENTLY UNUSED ##]


setInverseUnit

public void setInverseUnit(Quaternion q)
Sets this Quaternion to be the inverse of the given one, q. [## CURRENTLY UNUSED ##]


invertUnit

public void invertUnit()
Inverts this Quaternion, assuming it has unit length. [## CURRENTLY UNUSED ##]


normalize

public void normalize()
Normalizes this quaternion -- i.e. scales by 1 / length.


scaleXRotationAngle

public void scaleXRotationAngle(float scale)
Scales the angle of rotation in this quaternion by the given amount, assuming this quaternion represents a rotation about the X-axis, that is, this = (cos A/2, sin A/2, 0, 0).


fromAxisRotations

public void fromAxisRotations(float roll,
                              float pitch,
                              float yaw)
Set this Quaternion from the given "Euler" angle values (in degrees), that is, sequence of rotations about the axes.


toAxisRotations

public void toAxisRotations(float[] result)
Computes the "Euler" angles, that is, the sequence of rotations about the axes (roll [about X], pitch [about Y], yaw [about Z]), corresponding to this Quaternion -- with result values in degrees.


extractRotX

public void extractRotX(Quaternion qx)
Decomposes this quaternion into qx.qyz, where qx and qyz represent rotations about, respectively, the x-axis and some axis in the yz-plane, setting the given qx to be the first of the two factors.


scale

public void scale(float T)
Scales this quaternion by the specified fraction -- achieved using SLERP (spherical linear interpolation) with the identity quaternion (representing the null rotation).


slerp

public static void slerp(Quaternion qq,
                         Quaternion qa,
                         Quaternion qb,
                         float T)
Sets quaternion qq to be the SLERP (spherical linear interpolation), with fraction T, between the two (unit) quaternions qa, qb.


log

public Quaternion log()
Return a new Quaternion representing the logarithm of this one. [## CURRENTLY UNUSED ##]


exp

public Quaternion exp()
Return a new Quaternion representing the exponential of this one. [## CURRENTLY UNUSED ##]


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object