org.openmali.vecmath2
Class Quaternion4f

java.lang.Object
  extended by org.openmali.vecmath2.TupleNf<Quaternion4f>
      extended by org.openmali.vecmath2.Quaternion4f
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, TupleInterface<Quaternion4f>

public class Quaternion4f
extends TupleNf<Quaternion4f>
implements java.io.Externalizable

A 4 element quaternion represented by single precision floating point a,b,c,d coordinates. Inspired by Kenji Hiranabe's Quat4f implementation

See Also:
Serialized Form

Field Summary
static Quaternion4f IDENTITY
           
static Quaternion4f ROT_MINUS_90_DEG_BY_X_AXIS
           
static Quaternion4f ROT_MINUS_90_DEG_BY_Y_AXIS
           
static Quaternion4f ROT_MINUS_90_DEG_BY_Z_AXIS
           
static Quaternion4f ROT_PLUS_90_DEG_BY_X_AXIS
           
static Quaternion4f ROT_PLUS_90_DEG_BY_Y_AXIS
           
static Quaternion4f ROT_PLUS_90_DEG_BY_Z_AXIS
           
static Quaternion4f Z_UP_TO_Y_UP
           
static Quaternion4f ZERO
           
 
Fields inherited from class org.openmali.vecmath2.TupleNf
isDirty, roTrick, values
 
Constructor Summary
  Quaternion4f()
          Constructs and initializes a Quaternion4f to (0,0,0,0).
protected Quaternion4f(boolean readOnly)
          Constructs and initializes a Quaternion4f to (0,0,0,0).
protected Quaternion4f(boolean readOnly, float[] values, boolean[] isDirty, boolean copy)
          Constructs and initializes a Quaternion4f from the array of length 4.
protected Quaternion4f(boolean readOnly, float a, float b, float c, float d)
          Constructs and initializes a Quaternion4f from the specified xyzw coordinates.
protected Quaternion4f(boolean readOnly, Quaternion4f quat)
          Constructs and initializes a Quaternion4f from the array of length 4.
  Quaternion4f(float[] values)
          Constructs and initializes a Quaternion4f from the array of length 4.
  Quaternion4f(float a, float b, float c, float d)
          Constructs and initializes a Quaternion4f from the specified xyzw coordinates.
  Quaternion4f(Quaternion4f quat)
          Constructs and initializes a Quaternion4f from the array of length 4.
 
Method Summary
 float a()
           
 Quaternion4f a(float a)
          Sets the value of the A-element of this Quaternion.
 Quaternion4f asReadOnly()
          
 float b()
           
 Quaternion4f b(float b)
          Sets the value of the B-element of this Quaternion.
 float c()
           
 Quaternion4f c(float c)
          Sets the value of the C-element of this Quaternion.
 Quaternion4f clone()
          Creates and returns a copy of this object.
 Quaternion4f computeD()
          Computes the D-component from the A, B and C ones.
 Quaternion4f conjugate()
          Negates the value of each of this quaternion's a,b,c coordinates in place.
 Quaternion4f conjugate(Quaternion4f quat)
          Sets the value of this quaternion to the conjugate of quaternion quat.
 float d()
           
 Quaternion4f d(float d)
          Sets the value of the D-element of this Quaternion.
 boolean equals(java.lang.Object o)
          Returns true if the Object t1 is of type Tuple3f and all of the data members of t1 are equal to the corresponding data members in this Tuple3f.
static Quaternion4f fromPool()
          Allocates an Quaternion4f instance from the pool.
static Quaternion4f fromPool(float a, float b, float c, float d)
          Allocates an Quaternion4f instance from the pool.
static Quaternion4f fromPool(Quaternion4f quat)
          Allocates an Quaternion4f instance from the pool.
 float getA()
           
static void getAngles(Quaternion4f q1, Quaternion4f q2, Vector3f rotationAxis1, Vector3f rotationAxis2, Vector3f rotationAxis3, Vector3f passback)
          gets the angles around each provided axis required to move q1 to q2
 float getB()
           
 float getC()
           
 float getD()
           
 void getDirection(Vector3f rotationAxis, TupleNf<?> passbackNormal)
          if this quaternion is rotated by an infetesimal amount by the provided axis, then this quaterion values will move in the direction calulculated by this method.
 float getNorm()
           
 Quaternion4f getReadOnly()
          
 Vector3f getVectorComponent(Vector3f v)
           
 void interpolate(Quaternion4f quat2, float alpha)
          Performs a great circle interpolation between this quaternion and the quaternion parameter and places the result into this quaternion.
 float interpolateSLERP(Quaternion4f q1, Quaternion4f q2, float amount)
          A rotational interpolation returns a quaternion that is between the passed in arguments the amount is the bias toward q2. 0<=amount<=1 amount = 0 would return q1. amount =1 would return q2 uses an implementation of SLERP, uses trig so not too fast
static float interpolateSLERP(Quaternion4f q1, Quaternion4f q2, float amount, Quaternion4f result)
          A rotational interpolation returns a quaternion that is between the passed in arguments the amount is the bias toward q2. 0<=amount<=1 amount = 0 would return q1. amount =1 would return q2 uses an implementation of SLERP, uses trig so not too fast
 Quaternion4f invert()
          Sets the value of this quaternion to the quaternion inverse of itself.
 Quaternion4f invert(Quaternion4f quat)
          Sets the value of this quaternion to quaternion inverse of quaternion quat.
 Quaternion4f mul(Quaternion4f quat2)
          Sets the value of this quaternion to the quaternion product of itself and q1 (this = this * q1).
 Quaternion4f mul(Quaternion4f quat1, Quaternion4f quat2)
          Sets the value of this quaternion to the quaternion product of quaternions q1 and q2 (this = q1 * q2).
 Quaternion4f mul(Tuple3f t)
           
 Quaternion4f mul(Tuple3f t, Quaternion4f out)
           
 Quaternion4f mulInverse(Quaternion4f quat2)
          Multiplies this quaternion by the inverse of quaternion q1 and places the value into this quaternion.
 Quaternion4f mulInverse(Quaternion4f quat1, Quaternion4f quat2)
          Multiplies quaternion q1 by the inverse of quaternion q2 and places the value into this quaternion.
static Quaternion4f newReadOnly()
          Constructs and initializes a Quaternion4f to (0,0,0,0).
static Quaternion4f newReadOnly(float[] values)
          Constructs and initializes a Quaternion4f from the array of length 4.
static Quaternion4f newReadOnly(float a, float b, float c, float d)
          Constructs and initializes a Quaternion4f from the specified xyzw coordinates.
static Quaternion4f newReadOnly(Quaternion4f quat)
          Constructs and initializes a Quaternion4f from the array of length 4.
 Quaternion4f normalize()
          Normalizes the value of this quaternion in place.
 Quaternion4f normalize(Quaternion4f quat)
          Sets the value of this quaternion to the normalized value of quaternion quat.
 Quaternion4f set(AxisAngle3f aa3f)
          Sets the value of this quaternion to the equivalent rotation of teh AxisAngle argument.
 Quaternion4f set(float a, float b, float c, float d)
          Sets all values of this Quaternion4f to the specified ones.
 Quaternion4f set(Matrix3f mat)
          Sets the value of this quaternion to the rotational component of the passed matrix.
 Quaternion4f set(Matrix4f mat)
          Sets the value of this quaternion to the rotational component of the passed matrix.
 Quaternion4f set(Vector3f v, float w)
           
 Quaternion4f set(Vector4f v)
           
 Quaternion4f setA(float a)
          Sets the value of the A-element of this Quaternion.
 Quaternion4f setB(float b)
          Sets the value of the B-element of this Quaternion.
 Quaternion4f setC(float c)
          Sets the value of the C-element of this Quaternion.
 Quaternion4f setD(float d)
          Sets the value of the D-element of this Quaternion.
 Quaternion4f setDQDT(Vector3f angularVelocity, Quaternion4f passback)
          Changes in quaternion values wrt time for a given angular velocity dq/dt = .5 * (0, w) * q
 Quaternion4f setFromAxisAngle(float aaX, float aaY, float aaZ, float aaAngle)
          Sets the value of this quaternion to the equivalent rotation of teh AxisAngle argument.
 Quaternion4f setIdentity()
          Sets the value of this quaternion to the identity quaternion.
 Quaternion4f setMulScale(float scale, Vector3f v, Quaternion4f q)
          Computes scale * ( (v, 0f) * q ).
static void toPool(Quaternion4f o)
          Stores the given Quaternion4f instance in the pool.
<T extends Tuple3f>
T
transform(T vector)
           
<T extends Tuple3f>
T
transform(Tuple3f vector, T result)
           
static Quaternion4f weightedSLERP(Quaternion4f start, Quaternion4f target, Vector3f rotationAxis1, Vector3f rotationAxis2, Vector3f rotationAxis3, Vector3f weights, Vector3f anglePassback, Quaternion4f result)
          A generalization of SLERP.
 
Methods inherited from class org.openmali.vecmath2.TupleNf
absolute, absolute, add, add, addValue, clamp, clamp, clampMax, clampMax, clampMin, clampMin, deserialize, div, divValue, epsilonEquals, equals, fill, get, get, get, getSerializationBufferSize, getSize, getValue, hashCode, interpolate, isDirty, isReadOnly, mul, mulValue, negate, negate, readExternal, readFromBuffer, readFromBuffer, readFromBuffer, readFromBuffer, round, round, scale, scale, scaleAdd, scaleAdd, serialize, set, set, set, setClean, setValue, setZero, sub, sub, subValue, toString, writeExternal, writeToBuffer, writeToBuffer, writeToBuffer, writeToBuffer
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.io.Externalizable
readExternal, writeExternal
 

Field Detail

ZERO

public static final Quaternion4f ZERO

IDENTITY

public static final Quaternion4f IDENTITY

ROT_PLUS_90_DEG_BY_X_AXIS

public static final Quaternion4f ROT_PLUS_90_DEG_BY_X_AXIS

ROT_MINUS_90_DEG_BY_X_AXIS

public static final Quaternion4f ROT_MINUS_90_DEG_BY_X_AXIS

ROT_PLUS_90_DEG_BY_Y_AXIS

public static final Quaternion4f ROT_PLUS_90_DEG_BY_Y_AXIS

ROT_MINUS_90_DEG_BY_Y_AXIS

public static final Quaternion4f ROT_MINUS_90_DEG_BY_Y_AXIS

ROT_PLUS_90_DEG_BY_Z_AXIS

public static final Quaternion4f ROT_PLUS_90_DEG_BY_Z_AXIS

ROT_MINUS_90_DEG_BY_Z_AXIS

public static final Quaternion4f ROT_MINUS_90_DEG_BY_Z_AXIS

Z_UP_TO_Y_UP

public static final Quaternion4f Z_UP_TO_Y_UP
Constructor Detail

Quaternion4f

protected Quaternion4f(boolean readOnly,
                       float a,
                       float b,
                       float c,
                       float d)
Constructs and initializes a Quaternion4f from the specified xyzw coordinates.

Parameters:
readOnly -
a - the a coordinate
b - the b coordinate
c - the c coordinate
d - the d scalar component

Quaternion4f

protected Quaternion4f(boolean readOnly,
                       float[] values,
                       boolean[] isDirty,
                       boolean copy)
Constructs and initializes a Quaternion4f from the array of length 4.

Parameters:
readOnly -
values - the array of length 4 containing abcd in order
isDirty -
copy -

Quaternion4f

protected Quaternion4f(boolean readOnly,
                       Quaternion4f quat)
Constructs and initializes a Quaternion4f from the array of length 4.

Parameters:
readOnly -
quat - the array of length 4 containing abcd in order

Quaternion4f

protected Quaternion4f(boolean readOnly)
Constructs and initializes a Quaternion4f to (0,0,0,0).

Parameters:
readOnly -

Quaternion4f

public Quaternion4f(float a,
                    float b,
                    float c,
                    float d)
Constructs and initializes a Quaternion4f from the specified xyzw coordinates.

Parameters:
a - the a coordinate
b - the b coordinate
c - the c coordinate
d - the d scalar component

Quaternion4f

public Quaternion4f(float[] values)
Constructs and initializes a Quaternion4f from the array of length 4.

Parameters:
values - the array of length 4 containing abcd in order

Quaternion4f

public Quaternion4f(Quaternion4f quat)
Constructs and initializes a Quaternion4f from the array of length 4.

Parameters:
quat - the array of length 4 containing abcd in order

Quaternion4f

public Quaternion4f()
Constructs and initializes a Quaternion4f to (0,0,0,0).

Method Detail

setA

public final Quaternion4f setA(float a)
Sets the value of the A-element of this Quaternion.

Parameters:
a -
Returns:
itself

a

public final Quaternion4f a(float a)
Sets the value of the A-element of this Quaternion.

Parameters:
a -
Returns:
itself

setB

public final Quaternion4f setB(float b)
Sets the value of the B-element of this Quaternion.

Parameters:
b -
Returns:
itself

b

public final Quaternion4f b(float b)
Sets the value of the B-element of this Quaternion.

Parameters:
b -
Returns:
itself

setC

public final Quaternion4f setC(float c)
Sets the value of the C-element of this Quaternion.

Parameters:
c -
Returns:
itself

c

public final Quaternion4f c(float c)
Sets the value of the C-element of this Quaternion.

Parameters:
c -
Returns:
itself

setD

public final Quaternion4f setD(float d)
Sets the value of the D-element of this Quaternion.

Parameters:
d -
Returns:
itself

d

public final Quaternion4f d(float d)
Sets the value of the D-element of this Quaternion.

Parameters:
d -
Returns:
itself

getA

public final float getA()
Returns:
the value of the A-element of this Quaternion.

a

public final float a()
Returns:
the value of the A-element of this Quaternion.

getB

public final float getB()
Returns:
the value of the B-element of this Quaternion.

b

public final float b()
Returns:
the value of the B-element of this Quaternion.

getC

public final float getC()
Returns:
the value of the C-element of this Quaternion.

c

public final float c()
Returns:
the value of the C-element of this Quaternion.

getD

public final float getD()
Returns:
the value of the D-element of this Quaternion.

d

public final float d()
Returns:
the value of the D-element of this Quaternion.

computeD

public final Quaternion4f computeD()
Computes the D-component from the A, B and C ones.

Returns:
ifself

set

public final Quaternion4f set(float a,
                              float b,
                              float c,
                              float d)
Sets all values of this Quaternion4f to the specified ones.

Parameters:
a - the a element to use
b - the b element to use
c - the c element to use
d - the d element to use
Returns:
itself

getVectorComponent

public final Vector3f getVectorComponent(Vector3f v)

setIdentity

public final Quaternion4f setIdentity()
Sets the value of this quaternion to the identity quaternion.

Returns:
itself

set

public final Quaternion4f set(Matrix4f mat)
Sets the value of this quaternion to the rotational component of the passed matrix.

Parameters:
mat - the matrix4f
Returns:
itself

set

public final Quaternion4f set(Matrix3f mat)
Sets the value of this quaternion to the rotational component of the passed matrix.

Parameters:
mat - the matrix3f
Returns:
itself

setFromAxisAngle

public final Quaternion4f setFromAxisAngle(float aaX,
                                           float aaY,
                                           float aaZ,
                                           float aaAngle)
Sets the value of this quaternion to the equivalent rotation of teh AxisAngle argument.

Parameters:
aa3f - the axis-angle
Returns:
itself

set

public final Quaternion4f set(AxisAngle3f aa3f)
Sets the value of this quaternion to the equivalent rotation of teh AxisAngle argument.

Parameters:
aa3f - the axis-angle
Returns:
itself

set

public final Quaternion4f set(Vector3f v,
                              float w)

set

public final Quaternion4f set(Vector4f v)

getNorm

public final float getNorm()

invert

public final Quaternion4f invert(Quaternion4f quat)
Sets the value of this quaternion to quaternion inverse of quaternion quat.

Parameters:
quat - the quaternion to be inverted
Returns:
itself

invert

public final Quaternion4f invert()
Sets the value of this quaternion to the quaternion inverse of itself.

Returns:
itself

conjugate

public final Quaternion4f conjugate(Quaternion4f quat)
Sets the value of this quaternion to the conjugate of quaternion quat.

Parameters:
quat - the source Quaternion
Returns:
itself

conjugate

public final Quaternion4f conjugate()
Negates the value of each of this quaternion's a,b,c coordinates in place.

Returns:
itself

normalize

public final Quaternion4f normalize(Quaternion4f quat)
Sets the value of this quaternion to the normalized value of quaternion quat.

Parameters:
quat - the quaternion to be normalized.
Returns:
itself

normalize

public final Quaternion4f normalize()
Normalizes the value of this quaternion in place.

Returns:
itself

mul

public final Quaternion4f mul(Quaternion4f quat1,
                              Quaternion4f quat2)
Sets the value of this quaternion to the quaternion product of quaternions q1 and q2 (this = q1 * q2). Note that this is safe for aliasing (e.g. this can be q1 or q2).

Parameters:
quat1 - the first quaternion
quat2 - the second quaternion
Returns:
itself

mul

public final Quaternion4f mul(Quaternion4f quat2)
Sets the value of this quaternion to the quaternion product of itself and q1 (this = this * q1).

Parameters:
quat2 - the other quaternion
Returns:
itself

mulInverse

public final Quaternion4f mulInverse(Quaternion4f quat1,
                                     Quaternion4f quat2)
Multiplies quaternion q1 by the inverse of quaternion q2 and places the value into this quaternion. The value of both argument quaternions is preservered (this = q1 * q2^-1).

Parameters:
quat1 - the left quaternion
quat2 - the right quaternion
Returns:
itself

mulInverse

public final Quaternion4f mulInverse(Quaternion4f quat2)
Multiplies this quaternion by the inverse of quaternion q1 and places the value into this quaternion. The value of the argument quaternion is preserved (this = this * q^-1).

Parameters:
quat2 - the other quaternion
Returns:
itself

mul

public final Quaternion4f mul(Tuple3f t,
                              Quaternion4f out)

mul

public final Quaternion4f mul(Tuple3f t)

transform

public final <T extends Tuple3f> T transform(Tuple3f vector,
                                             T result)

transform

public final <T extends Tuple3f> T transform(T vector)

setMulScale

public final Quaternion4f setMulScale(float scale,
                                      Vector3f v,
                                      Quaternion4f q)
Computes scale * ( (v, 0f) * q ).

Parameters:
scale -
v -
q -
Returns:
itself

setDQDT

public final Quaternion4f setDQDT(Vector3f angularVelocity,
                                  Quaternion4f passback)
Changes in quaternion values wrt time for a given angular velocity dq/dt = .5 * (0, w) * q

Parameters:
angularVelocity -
passback -
Returns:
itself

interpolate

public void interpolate(Quaternion4f quat2,
                        float alpha)
Performs a great circle interpolation between this quaternion and the quaternion parameter and places the result into this quaternion.

Specified by:
interpolate in interface TupleInterface<Quaternion4f>
Overrides:
interpolate in class TupleNf<Quaternion4f>
Parameters:
quat2 - the other quaternion
alpha - the alpha interpolation parameter

interpolateSLERP

public static float interpolateSLERP(Quaternion4f q1,
                                     Quaternion4f q2,
                                     float amount,
                                     Quaternion4f result)
A rotational interpolation returns a quaternion that is between the passed in arguments the amount is the bias toward q2. 0<=amount<=1 amount = 0 would return q1. amount =1 would return q2 uses an implementation of SLERP, uses trig so not too fast

Parameters:
q1 - unit quaternion 1
q2 - unit quaternion 2
amount - interpolation parameter, between 0 and 1
result - the passback of the result
Returns:
omega, the TOTAL angle between q1 and q2 on the unit hypershpere, which the algorithm then scales by amount (note not the rotational angle, you must divide by 2 to get this

interpolateSLERP

public float interpolateSLERP(Quaternion4f q1,
                              Quaternion4f q2,
                              float amount)
A rotational interpolation returns a quaternion that is between the passed in arguments the amount is the bias toward q2. 0<=amount<=1 amount = 0 would return q1. amount =1 would return q2 uses an implementation of SLERP, uses trig so not too fast

Parameters:
q1 - unit quaternion 1
q2 - unit quaternion 2
amount - interpolation parameter, between 0 and 1
Returns:
omega, the TOTAL angle between q1 and q2 on the unit hypershpere, which the algorithm then scales by amount (note not the rotational angle, you must divide by 2 to get this

weightedSLERP

public static Quaternion4f weightedSLERP(Quaternion4f start,
                                         Quaternion4f target,
                                         Vector3f rotationAxis1,
                                         Vector3f rotationAxis2,
                                         Vector3f rotationAxis3,
                                         Vector3f weights,
                                         Vector3f anglePassback,
                                         Quaternion4f result)
A generalization of SLERP. Instead of lambda along the shortest, constant velocity path, the movement to the target rotation is broken into 3 independant rotational components at the start_b rotation. The returned rotation is an interpolation of these three components, controlled by three parameters. If all the parameters are of the same value, then this method is equivelent to SLERP. This is needed by JOODE to allow different angular ERP parameters for different dimentions for angular constraints in certain joints input axis should be normalized

Parameters:
start -
target -
rotationAxis1 -
rotationAxis2 -
rotationAxis3 -
weights - the weight to apply to each rotation component in order (technically not really a vector)
anglePassback - this can be null, if not null, the angle each component
result -

getDirection

public final void getDirection(Vector3f rotationAxis,
                               TupleNf<?> passbackNormal)
if this quaternion is rotated by an infetesimal amount by the provided axis, then this quaterion values will move in the direction calulculated by this method. This is the tangital vector to the quaternion unit circle in the direction of the rotation axis (surely this would imply that it is equaly to dq_dt but this does not seem to be the case)


getAngles

public static void getAngles(Quaternion4f q1,
                             Quaternion4f q2,
                             Vector3f rotationAxis1,
                             Vector3f rotationAxis2,
                             Vector3f rotationAxis3,
                             Vector3f passback)
gets the angles around each provided axis required to move q1 to q2

Parameters:
passback - each angle is put in an element of the 3D vector in the order of the rotation axis

asReadOnly

public Quaternion4f asReadOnly()

Specified by:
asReadOnly in class TupleNf<Quaternion4f>
Returns:
a new instance sharing the values array with this instance. The new instance is read-only. Changes to this instance will be reflected in the new read-only-instance.
See Also:
TupleNf.getReadOnly()

getReadOnly

public Quaternion4f getReadOnly()

Specified by:
getReadOnly in class TupleNf<Quaternion4f>
Returns:
a single instance sharing the values array with this instance (one unique instance per 'master-instance'). The instance is read-only. Changes to this instance will be reflected in the read-only-instance.
See Also:
TupleNf.asReadOnly()

equals

public final boolean equals(java.lang.Object o)
Returns true if the Object t1 is of type Tuple3f and all of the data members of t1 are equal to the corresponding data members in this Tuple3f.

Overrides:
equals in class TupleNf<Quaternion4f>
Parameters:
o - the Object with which the comparison is made
Returns:
true or false

clone

public Quaternion4f clone()
Creates and returns a copy of this object.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this instance.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
Cloneable

newReadOnly

public static Quaternion4f newReadOnly(float a,
                                       float b,
                                       float c,
                                       float d)
Constructs and initializes a Quaternion4f from the specified xyzw coordinates.

Parameters:
a - the a coordinate
b - the b coordinate
c - the c coordinate
d - the d scalar component

newReadOnly

public static Quaternion4f newReadOnly(float[] values)
Constructs and initializes a Quaternion4f from the array of length 4.

Parameters:
values - the array of length 4 containing abcd in order

newReadOnly

public static Quaternion4f newReadOnly(Quaternion4f quat)
Constructs and initializes a Quaternion4f from the array of length 4.

Parameters:
quat - the array of length 4 containing abcd in order

newReadOnly

public static Quaternion4f newReadOnly()
Constructs and initializes a Quaternion4f to (0,0,0,0).


fromPool

public static Quaternion4f fromPool()
Allocates an Quaternion4f instance from the pool.


fromPool

public static Quaternion4f fromPool(float a,
                                    float b,
                                    float c,
                                    float d)
Allocates an Quaternion4f instance from the pool.


fromPool

public static Quaternion4f fromPool(Quaternion4f quat)
Allocates an Quaternion4f instance from the pool.


toPool

public static void toPool(Quaternion4f o)
Stores the given Quaternion4f instance in the pool.

Parameters:
o -