jme.math
Class Quaternion

java.lang.Object
  extended byjme.math.Quaternion

public class Quaternion
extends java.lang.Object

Quaternion defines a single example of a more general class of hypercomplex numbers. Quaternions extends a rotation in three dimensions to a rotation in four dimensions. This avoids "gimbal lock" and allows for smooth continuous rotation. Quaternion is defined by four floating point numbers: {x y z w}.

Version:
$Id: Quaternion.java,v 1.5 2003/08/22 02:26:48 mojomonkey Exp $
Author:
Mark Powell

Field Summary
 float w
           
 float x
           
 float y
           
 float z
           
 
Constructor Summary
Quaternion()
          Constructor instantiates a new Quaternion object initializing all values to zero.
Quaternion(float[] angles)
          Constructor instantiates a new Quaternion object from a collection of rotation angles.
Quaternion(float x, float y, float z, float w)
          Constructor instantiates a new Quaternion object from the given list of parameters.
Quaternion(Quaternion q)
          Constructor instantiates a new Quaternion object from an existing quaternion, creating a copy.
Quaternion(Quaternion q1, Quaternion q2, float interp)
          Constructor instantiates a new Quaternion object from an interpolation between two other quaternions.
 
Method Summary
 Quaternion add(Quaternion q)
          add adds the values of this quaternion to those of the parameter quaternion.
 float dot(Quaternion q)
          dot calculates and returns the dot product of this quaternion with that of the parameter quaternion.
 void fromAngleAxis(float angle, Vector axis)
          fromAngleAxis sets this quaternion to the values specified by an angle and an axis of rotation.
 void fromAngles(float[] angles)
          fromAngles builds a quaternion from the Euler rotation angles (x,y,z).
 void fromMatrix(float[] matrix, int rowColumnCount)
          fromMatrix creates a quaternion from the rotational matrix.
 Quaternion inverse()
          inverse returns the inverse of this quaternion as a new quaternion.
static void main(java.lang.String[] args)
           
 Quaternion mult(float scalar)
          mult multiplies this quaternion by a parameter scalar.
 Quaternion mult(Quaternion q)
          mult multiplies this quaternion by a parameter quaternion.
 void negate()
          negate inverts the values of the quaternion.
 float norm()
          norm returns the norm of this quaternion.
 Quaternion slerp(Quaternion q1, Quaternion q2, float t)
          slerp sets this quaternion's value as an interpolation between two other quaternions.
 Quaternion subtract(Quaternion q)
          subtract subtracts the values of the parameter quaternion from those of this quaternion.
 float toAngleAxis(Vector axis)
          toAngleAxis sets a given angle and axis to that represented by the current quaternion.
 float[] toMatrix()
          getMatrix converts the values of this quaternion into a 4x4 matrix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

x

public float x

y

public float y

z

public float z

w

public float w
Constructor Detail

Quaternion

public Quaternion()
Constructor instantiates a new Quaternion object initializing all values to zero.


Quaternion

public Quaternion(float x,
                  float y,
                  float z,
                  float w)
Constructor instantiates a new Quaternion object from the given list of parameters.

Parameters:
x - the x value of the quaternion.
y - the y value of the quaternion.
z - the z value of the quaternion.
w - the w value of the quaternion.

Quaternion

public Quaternion(float[] angles)
Constructor instantiates a new Quaternion object from a collection of rotation angles.

Parameters:
angles - the angles of rotation that will define the Quaternion.

Quaternion

public Quaternion(Quaternion q1,
                  Quaternion q2,
                  float interp)
Constructor instantiates a new Quaternion object from an interpolation between two other quaternions.

Parameters:
q1 - the first quaternion.
q2 - the second quaternion.
interp - the amount to interpolate between the two quaternions.

Quaternion

public Quaternion(Quaternion q)
Constructor instantiates a new Quaternion object from an existing quaternion, creating a copy.

Parameters:
q - the quaternion to copy.
Method Detail

fromAngles

public void fromAngles(float[] angles)
fromAngles builds a quaternion from the Euler rotation angles (x,y,z).

Parameters:
angles - the Euler angles of rotation.

fromAngleAxis

public void fromAngleAxis(float angle,
                          Vector axis)
fromAngleAxis sets this quaternion to the values specified by an angle and an axis of rotation.

Parameters:
angle - the angle to rotate.
axis - the axis of rotation.

fromMatrix

public void fromMatrix(float[] matrix,
                       int rowColumnCount)
fromMatrix creates a quaternion from the rotational matrix. A quaternion can be created from a 3x3 or 4x4 matrix. If a 3x3 matrix is passed, it will be converted into a 4x4.

Parameters:
matrix - the matrix to generate the quaternion from.
rowColumnCount - the number of rows/colums (3 or 4).

toMatrix

public float[] toMatrix()
getMatrix converts the values of this quaternion into a 4x4 matrix.

Returns:
the matrix representation of this quaternion.

toAngleAxis

public float toAngleAxis(Vector axis)
toAngleAxis sets a given angle and axis to that represented by the current quaternion. The values are stored as following: The axis is provided as a parameter and built by the method, the angle is returned as a float.

Parameters:
axis - the object to contain the axis.
Returns:
the angle of rotation.

slerp

public Quaternion slerp(Quaternion q1,
                        Quaternion q2,
                        float t)
slerp sets this quaternion's value as an interpolation between two other quaternions.

Parameters:
q1 - the first quaternion.
q2 - the second quaternion.

add

public Quaternion add(Quaternion q)
add adds the values of this quaternion to those of the parameter quaternion. The result is returned as a new quaternion.

Parameters:
q - the quaternion to add to this.
Returns:
the new quaternion.

subtract

public Quaternion subtract(Quaternion q)
subtract subtracts the values of the parameter quaternion from those of this quaternion. The result is returned as a new quaternion.

Parameters:
q - the quaternion to subtract from this.
Returns:
the new quaternion.

mult

public Quaternion mult(Quaternion q)
mult multiplies this quaternion by a parameter quaternion. The result is returned as a new quaternion. It should be noted that quaternion multiplication is not cummulative so q * p != p * q.

Parameters:
q - the quaternion to multiply this quaternion by.
Returns:
the new quaternion.

mult

public Quaternion mult(float scalar)
mult multiplies this quaternion by a parameter scalar. The result is returned as a new quaternion.

Returns:
the new quaternion.

dot

public float dot(Quaternion q)
dot calculates and returns the dot product of this quaternion with that of the parameter quaternion.

Parameters:
q - the quaternion to calculate the dot product of.
Returns:
the dot product of this and the parameter quaternion.

norm

public float norm()
norm returns the norm of this quaternion. This is the dot product of this quaternion with itself.

Returns:
the norm of the quaternion.

inverse

public Quaternion inverse()
inverse returns the inverse of this quaternion as a new quaternion. If this quaternion does not have an inverse (if it's norma is 0 or less), then null is returned.

Returns:
the inverse of this quaternion or null if the inverse does not exist.

negate

public void negate()
negate inverts the values of the quaternion.


main

public static void main(java.lang.String[] args)