net.jinx.math
Class Quaternion

java.lang.Object
  extended by net.jinx.math.Quaternion

public class Quaternion
extends java.lang.Object

Quaternion is effectively, a 4 element vector with special functionality. This class is most often used for storing rotation data. This class is built from a Vector instance and a float for the additional w coordinate. The Vector holds data describing the axis of rotation and the w component holds the magnitude of the rotation.

Quaternions have other uses, however.


Field Summary
static Quaternion zero
           
 
Constructor Summary
Quaternion()
          Constructs a Quaternion with all zero components.
Quaternion(float[] vec)
          Constructs a new Quaternion with the given W/X/Y/Z coordinates.
Quaternion(float x, float y, float z, float w)
          Constructs a new Quaternion with the given W/X/Y/Z coordinates.
Quaternion(java.lang.String s)
          Constructs a new Quaternion by parsing the given String.
Quaternion(Vector v, float w)
          Constructs a new Quaternion from v and w.
 
Method Summary
 Quaternion add(float n)
           
 Quaternion add(Quaternion q)
           
 Quaternion conjugate()
           
 Quaternion divide(float n)
           
 Quaternion divide(Quaternion q)
           
 boolean equals(java.lang.Object obj)
           
 void fillFloatArray(float[] fa)
          Fills a length 4 float array with the values for getX(), getY(), getZ() and getW().
 Vector getV()
           
 float getW()
          Provides the W component.
 float getX()
          Provides the X coordinate.
 float getY()
          Provides the Y coordinate.
 float getZ()
          Provides the Z coordinate.
 int hashCode()
          Returns the hash code for this Quaternion.
 Quaternion invert()
           
 float magnitude()
           
 Quaternion multiply(float n)
           
 Quaternion multiply(Quaternion q2)
           
 Quaternion normalize()
           
 Quaternion subtract(float n)
           
 Quaternion subtract(Quaternion q)
           
 float[] toFloatArray()
          Converts this Quaternion to a float array.
 java.lang.String toString()
          Provides a String representation of this Vector.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

zero

public static final Quaternion zero
Constructor Detail

Quaternion

public Quaternion()
Constructs a Quaternion with all zero components.


Quaternion

public Quaternion(float x,
                  float y,
                  float z,
                  float w)
Constructs a new Quaternion with the given W/X/Y/Z coordinates.

Parameters:
w - the W coordinate.
x - the X coordinate.
y - the Y coordinate.
z - the Z coordinate.

Quaternion

public Quaternion(float[] vec)
Constructs a new Quaternion with the given W/X/Y/Z coordinates.

Parameters:
vec - the coordinates in an array.

Quaternion

public Quaternion(Vector v,
                  float w)
Constructs a new Quaternion from v and w.

Parameters:
v - the Vector component for this Quaternion.
w - the W component for this Quaternion.

Quaternion

public Quaternion(java.lang.String s)
Constructs a new Quaternion by parsing the given String.

Parameters:
s - the String to parse.
Method Detail

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

getW

public float getW()
Provides the W component.

Returns:
the W component.

getV

public Vector getV()

getX

public float getX()
Provides the X coordinate.

Returns:
the X coordinate.

getY

public float getY()
Provides the Y coordinate.

Returns:
the Y coordinate.

getZ

public float getZ()
Provides the Z coordinate.

Returns:
the Z coordinate.

add

public Quaternion add(float n)

add

public Quaternion add(Quaternion q)

subtract

public Quaternion subtract(float n)

subtract

public Quaternion subtract(Quaternion q)

multiply

public Quaternion multiply(float n)

multiply

public Quaternion multiply(Quaternion q2)

conjugate

public Quaternion conjugate()

invert

public Quaternion invert()

divide

public Quaternion divide(float n)

divide

public Quaternion divide(Quaternion q)

magnitude

public float magnitude()

normalize

public Quaternion normalize()

toFloatArray

public float[] toFloatArray()
Converts this Quaternion to a float array.

Returns:
the float array.

fillFloatArray

public void fillFloatArray(float[] fa)
Fills a length 4 float array with the values for getX(), getY(), getZ() and getW().

Parameters:
fa - the float array to fill.
Throws:
java.lang.IllegalArgumentException - if fa is not length 4.

toString

public java.lang.String toString()
Provides a String representation of this Vector.

Overrides:
toString in class java.lang.Object
Returns:
the String.

hashCode

public int hashCode()
Returns the hash code for this Quaternion.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code of the magnitude as per Float.floatToIntBits(float).