net.java.dev.joode.util
Class Quaternion

java.lang.Object
  extended by net.java.dev.joode.util.Real
      extended by net.java.dev.joode.util.Vector4
          extended by net.java.dev.joode.util.Quaternion

public class Quaternion
extends Vector4

quaternions have the format: (s,vx,vy,vz) where (vx,vy,vz) is the "rotation axis" and s is the "rotation angle".


Field Summary
static Vector4 c1
           
static Vector4 c2
           
static Vector4 c3
           
static Vector4 n1
           
static Vector4 n2
           
static Vector4 n3
           
static Vector4 r1
           
static Vector4 r2
           
static Vector4 r3
           
 
Fields inherited from class net.java.dev.joode.util.Vector4
additionalConstraint, linearHyperplaneCooeffecients, linearHyperplaneRHS, modifiedNormals
 
Fields inherited from class net.java.dev.joode.util.Real
m
 
Constructor Summary
Quaternion()
          Quatenion contrsucted with w = 1 and the rest 0
Quaternion(float s, float vx, float vy, float vz)
           
Quaternion(Quaternion q)
          Constructs a copy of a specified quaternion.
 
Method Summary
static boolean epsilonEquals(Quaternion a, Quaternion b, float e)
          checks if two quaternions represent the rotation.
 void getDirection(Vector3 rotationAxix, Vector4 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.
 Vector3 getEuler(Vector3 passback)
          does not appear to work in practice, based on: does not work: http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
 float getNorm()
           
static float interpolateSLERP(Vector4 q1, Vector4 q2, float amount, Vector4 result)
          A rotational interpolation returns a quaternion that is between the passed in arguments the amount is the bias toward q2.
 void invert()
          Inverts this quaternion.
static Vector3 invMulScale(Quaternion q, float scale, Quaternion result, Vector3 passback)
          returns the vector3 that would satisfy the following use of mulScale t.mulScale(v, s, r); v = invMulScale(t, s, r, v);
 Quaternion mul(Quaternion q, Quaternion result)
          Multiplication as defined by quaternion algebra.
 Quaternion mulScale(Vector3 v, float scale)
           
 Quaternion mulScale(Vector3 v, float scale, Quaternion result)
          v is assumed to be a quat with w = 0 result = scale * q(o,v) * this note the arguments are the opposite way around to the quat definition of multiply (in order for the vector to be an argument)
 void set(Matrix3 R)
          sets this quaternion to be the same as the passed in rotation matrix
 void setAxisAngle(float angle, Vector3 axis)
          sets this quaternion to be an axis with angle rotation
 void setEuler(float ax, float ay, float az)
          does not appear to work in practice, based on: does not work: http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
 void setEuler(Vector3 v)
           
static Quaternion setRandomQuation(Quaternion q)
           
 void toMatrix(Matrix3 R)
           
static Quaternion weightedSLERP(Quaternion start, Quaternion target, Vector3 rotationAxis1, Vector3 rotationAxis2, Vector3 rotationAxis3, Vector3 weights, Vector3 anglePassback, Quaternion result)
          A generalization of SLERP.
 
Methods inherited from class net.java.dev.joode.util.Vector4
add, getLinearHyperPlaneNormal, set, setRandomVector, sub, toString
 
Methods inherited from class net.java.dev.joode.util.Real
add, aquireDirtyInstance, aquireInstance, dot, dot, epsilonEquals, epsilonEquals, fill, get, length, lengthSquared, max, min, norm, normalize, releaseInstance, scale, set, set, setZero, size, sub
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

n1

public static final Vector4 n1

n2

public static final Vector4 n2

n3

public static final Vector4 n3

c1

public static final Vector4 c1

c2

public static final Vector4 c2

c3

public static final Vector4 c3

r1

public static final Vector4 r1

r2

public static final Vector4 r2

r3

public static final Vector4 r3
Constructor Detail

Quaternion

public Quaternion()
Quatenion contrsucted with w = 1 and the rest 0


Quaternion

public Quaternion(float s,
                  float vx,
                  float vy,
                  float vz)

Quaternion

public Quaternion(Quaternion q)
Constructs a copy of a specified quaternion.

Method Detail

set

public void set(Matrix3 R)
sets this quaternion to be the same as the passed in rotation matrix

Parameters:
R -

toMatrix

public void toMatrix(Matrix3 R)

setRandomQuation

public static Quaternion setRandomQuation(Quaternion q)

mul

public Quaternion mul(Quaternion q,
                      Quaternion result)
Multiplication as defined by quaternion algebra. It computes result <- this * q. It corresponds to the ODE call dQMultiply0(result,this,q). this * q = result

Parameters:
q - a quaternion to be multiplied by this
result - receives the result. It must not be either this or q.

mulScale

public Quaternion mulScale(Vector3 v,
                           float scale)

mulScale

public Quaternion mulScale(Vector3 v,
                           float scale,
                           Quaternion result)
v is assumed to be a quat with w = 0 result = scale * q(o,v) * this note the arguments are the opposite way around to the quat definition of multiply (in order for the vector to be an argument)

Parameters:
v -
result -
Returns:

invMulScale

public static Vector3 invMulScale(Quaternion q,
                                  float scale,
                                  Quaternion result,
                                  Vector3 passback)
returns the vector3 that would satisfy the following use of mulScale t.mulScale(v, s, r); v = invMulScale(t, s, r, v);


setAxisAngle

public void setAxisAngle(float angle,
                         Vector3 axis)
sets this quaternion to be an axis with angle rotation

Parameters:
angle -
axis -

setEuler

public void setEuler(Vector3 v)

setEuler

public void setEuler(float ax,
                     float ay,
                     float az)
does not appear to work in practice, based on: does not work: http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles


getEuler

public Vector3 getEuler(Vector3 passback)
does not appear to work in practice, based on: does not work: http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles


interpolateSLERP

public static float interpolateSLERP(Vector4 q1,
                                     Vector4 q2,
                                     float amount,
                                     Vector4 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

weightedSLERP

public static Quaternion weightedSLERP(Quaternion start,
                                       Quaternion target,
                                       Vector3 rotationAxis1,
                                       Vector3 rotationAxis2,
                                       Vector3 rotationAxis3,
                                       Vector3 weights,
                                       Vector3 anglePassback,
                                       Quaternion 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 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:
weights - the weight to apply to each rotation component in order (technically not really a vector)
Returns:

getDirection

public void getDirection(Vector3 rotationAxix,
                         Vector4 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

Parameters:
rotationAxix -
passbackNormal -

invert

public void invert()
Inverts this quaternion.


epsilonEquals

public static boolean epsilonEquals(Quaternion a,
                                    Quaternion b,
                                    float e)
checks if two quaternions represent the rotation. In quaternion geometry this willbe true if the elements are the same, or all the elemants are the negative of the other

Parameters:
a -
b -
e -
Returns:

getNorm

public float getNorm()