VeaR/JEllipse

pl.krakow.cmuj.bioinformatics.jellipse.mathtoolkit
Class Quaternion

java.lang.Object
  extended by pl.krakow.cmuj.bioinformatics.jellipse.mathtoolkit.Quaternion

public class Quaternion
extends java.lang.Object

Contains tools to perform fast rotations and is not intended to be complete, sufficient or robust for any other task related to quaternions.


Field Summary
(package private)  float[] q
           
 
Constructor Summary
Quaternion()
          Creates new unit quaternon (w == 1.f).
Quaternion(float[][] matrix)
          Creates new quaternion from a matrix given.
Quaternion(float roll, float pitch, float yaw)
          Creates a new instance of the Quaternion with given angles of rotation.
 
Method Summary
 float getW()
          Gets the scalar value of the quaternion.
 float getX()
          Gets the first vector value of the quaternion.
 float getY()
          Gets the second vector value of the quaternion.
 float getZ()
          Gets the third vector value of the quaternion.
 Quaternion multiply(Quaternion q2)
          Multiplies current quaternion (as left one) with another (as right one).
 void setW(float w)
          Sets the scalar value of the quaternion.
 void setX(float x)
          Sets the first vector value of the quaternion.
 void setY(float y)
          Sets the second vector value of the quaternion.
 void setZ(float z)
          Sets the third vector value of the quaternion.
 float[] toRotationMatrix16()
          Converts the current quaternion to a rotation matrix with 16 elements.
 float[][] toRotationMatrix4x4()
          Converts the current quaternion to a rotation matrix 4x4.
 float[] toRotationMatrix9()
          Converts the current quaternion to a rotation matrix with 9 elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

q

float[] q
Constructor Detail

Quaternion

public Quaternion()
Creates new unit quaternon (w == 1.f).


Quaternion

public Quaternion(float[][] matrix)
Creates new quaternion from a matrix given.

Parameters:
matrix - base 4x4 matrix

Quaternion

public Quaternion(float roll,
                  float pitch,
                  float yaw)
Creates a new instance of the Quaternion with given angles of rotation.

Method Detail

getW

public float getW()
Gets the scalar value of the quaternion.

Returns:
the scalar value of the quaternion

getX

public float getX()
Gets the first vector value of the quaternion.

Returns:
the first vector value of the quaternion

getY

public float getY()
Gets the second vector value of the quaternion.

Returns:
the second vector value of the quaternion

getZ

public float getZ()
Gets the third vector value of the quaternion.

Returns:
the third vector value of the quaternion

setW

public void setW(float w)
Sets the scalar value of the quaternion.

Parameters:
w - the scalar value of the quaternion to be set

setX

public void setX(float x)
Sets the first vector value of the quaternion.

Parameters:
x - the first vector value of the quaternion to be set

setY

public void setY(float y)
Sets the second vector value of the quaternion.

Parameters:
y - the second vector value of the quaternion to be set

setZ

public void setZ(float z)
Sets the third vector value of the quaternion.

Parameters:
z - the third vector value of the quaternion to be set

multiply

public Quaternion multiply(Quaternion q2)
Multiplies current quaternion (as left one) with another (as right one). This multiplication is noncomutative.

Parameters:
q2 - another quaternion (right in multiplication)
Returns:
quaternion as the product of multiplication

toRotationMatrix4x4

public float[][] toRotationMatrix4x4()
Converts the current quaternion to a rotation matrix 4x4.

Returns:
rotation matrix 4x4 (2-dim array)

toRotationMatrix16

public float[] toRotationMatrix16()
Converts the current quaternion to a rotation matrix with 16 elements.

Returns:
rotation matrix with 16 elements (1-dim array)

toRotationMatrix9

public float[] toRotationMatrix9()
Converts the current quaternion to a rotation matrix with 9 elements. (Implementation adapted from NeHe OpenGL tutorials.)

Returns:
rotation matrix with 9 elements (1-dim array)

VeaR/JEllipse