Kanzi Java API
Quaternion Class Reference

Quaternions represent rotation around an axis, defined by quaternion components x, y, z and w. More...

Inheritance diagram for Quaternion:
[legend]

Public Member Functions

 Quaternion (long cPtr, boolean cMemoryOwn)
 
 Quaternion ()
 Default constructor, initializes the quaternion components to identity, representing no rotation (x=0, y=0, z=0, w=1).
 
 Quaternion (float x, float y, float z, float w)
 Constructor, initializes the quaternion components to x, y, z and w. More...
 
Quaternion conjugated ()
 Get conjugated copy of this quaternion. More...
 
synchronized void delete ()
 
Quaternion divideByScalar (float scalar)
 
boolean equals (Object obj)
 
float get (long index)
 
float getW ()
 Get the w component of the quaternion. More...
 
float getX ()
 Get the x component of the quaternion. More...
 
float getY ()
 Get the y component of the quaternion. More...
 
float getZ ()
 Get the z component of the quaternion. More...
 
Quaternion multiplyByScalar (float scalar)
 
Quaternion normalized ()
 Get normalized copy of this quaternion. More...
 
void set (long index, float v)
 
void setW (float w)
 Sets the w component of the quaternion. More...
 
void setX (float x)
 Sets the x component of the quaternion. More...
 
void setY (float y)
 Sets the y component of the quaternion. More...
 
void setZ (float z)
 Sets the z component of the quaternion. More...
 

Static Public Member Functions

static Vector3 calculateEulerAngles (Quaternion quaternion)
 
static Quaternion componentWiseMultiply (Quaternion q1, Quaternion q2)
 
static Quaternion createFromEulerAngles (Vector3 anglesInRadians)
 Creates a quaternion from Euler angles. More...
 
static Quaternion createFromEulerAngles (float rotationX, float rotationY, float rotationZ)
 Creates a quaternion from Euler angles. More...
 
static Quaternion createFromVector (Vector3 axis, float angleInRadians)
 Creates quaternion from axis and angle. More...
 
static Quaternion divide (Quaternion q, float scalar)
 
static float dotProduct (Quaternion q1, Quaternion q2)
 
static long getCPtr (Quaternion obj)
 
static Quaternion inverse (Quaternion q)
 
static Quaternion matrix4x4ToQuaternion (Matrix4x4 matrix)
 
static Quaternion multiply (Quaternion q, float scalar)
 
static Quaternion multiply (Quaternion left, Quaternion right)
 
static Quaternion quaternionSlerp (Quaternion q1, Quaternion q2, float interpolationTime)
 
static Quaternion quaternionSlerpLongerPath (Quaternion q1, Quaternion q2, float interpolationTime)
 
static Matrix4x4 quaternionToMatrix4x4 (Quaternion quaternion)
 
static Vector3 rotateVector (Quaternion quaternion, Vector3 vector)
 

Protected Member Functions

void finalize ()
 

Protected Attributes

transient boolean swigCMemOwn
 

Detailed Description

Quaternions represent rotation around an axis, defined by quaternion components x, y, z and w.


Quaternions are compact, do not suffer from gimbal lock and can be easily interpolated.
Kanzi Engine uses quaternions internally to represent all rotations.
Quaternions are based on complex numbers and are not easy to understand intuitively. You almost never access or modify the individual components.
In most cases you take existing rotations and use them to construct new rotations (e.g. to smoothly interpolate between two rotations).
You can use the Quaternion operator * to rotate one rotation by another, or to rotate a vector by a rotation.
See operator*(const Quaternion& q1, const Quaternion& q2).
See rotateVector(const Quaternion& quaternion, Vector3 vector).

Constructor & Destructor Documentation

Quaternion ( float  x,
float  y,
float  z,
float  w 
)

Constructor, initializes the quaternion components to x, y, z and w.


Parameters
xx component of the quaternion.
yy component of the quaternion.
zz component of the quaternion.
ww component of the quaternion.

Member Function Documentation

Quaternion conjugated ( )

Get conjugated copy of this quaternion.

Conjugation inverses the quaternion axis components x, y and z.
Use this to get the inverse rotation of a quaternion.

Returns
Conjugated quaternion.
static Quaternion createFromEulerAngles ( Vector3  anglesInRadians)
static

Creates a quaternion from Euler angles.


Kanzi Engine represents Euler angles as Tait-Bryan angles where the rotations are applied in the order x, y and z.

Parameters
anglesInRadiansEuler angles in radians.
Returns
Rotated quaternion.
static Quaternion createFromEulerAngles ( float  rotationX,
float  rotationY,
float  rotationZ 
)
static

Creates a quaternion from Euler angles.


Kanzi Engine represents Euler angles as Tait-Bryan angles where the rotations are applied in the order x, y and z.

Parameters
rotationXRotation angle around the x axis in radians.
rotationYRotation angle around the y axis in radians.
rotationZRotation angle around the z axis in radians.
Returns
Rotated quaternion.
static Quaternion createFromVector ( Vector3  axis,
float  angleInRadians 
)
static

Creates quaternion from axis and angle.

Use this to create a quaternion from axis of rotation and angle in radians.

Parameters
axisAxis components in Vector3(x, y, z).
angleInRadiansAngle in radians.
Returns
Rotated quaternion.
float getW ( )

Get the w component of the quaternion.


Returns
The w component.
float getX ( )

Get the x component of the quaternion.


Returns
The x component.
float getY ( )

Get the y component of the quaternion.


Returns
The y component.
float getZ ( )

Get the z component of the quaternion.


Returns
The z component.
Quaternion normalized ( )

Get normalized copy of this quaternion.

Normalized quaternion is called an unit quaternion.
Calculates the magnitude from the dot product of the quaternion components, and divides all the quaternion components with the magnitude.
Use this when rotating or transforming a vector with a quaternion, and when generating a rotation or transformation matrix from quaternion.
Using unnormalized quaternion in calculations can lead to floating point rounding errors. The errors that result from using an unnormalized
quaternion in calculations are proportional to the square of the quaternion's magnitude.

Returns
Normalized quaternion.
void setW ( float  w)

Sets the w component of the quaternion.


Parameters
wThe new value of the w component.
void setX ( float  x)

Sets the x component of the quaternion.


Parameters
xThe new value of the x component.
void setY ( float  y)

Sets the y component of the quaternion.


Parameters
yThe new value of the y component.
void setZ ( float  z)

Sets the z component of the quaternion.


Parameters
zThe new value of the z component.