Quaternions represent rotation around an axis, defined by quaternion components x, y, z and w. More...
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) |
Divides each quaternion component with a scalar and returns the result. More... | |
boolean | equals (Object obj) |
float | get (long index) |
Returns individual quaternion element value at index. More... | |
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) |
Multiplies each quaternion component with a scalar. More... | |
Quaternion | normalized () |
Get normalized copy of this quaternion. More... | |
void | set (long index, float v) |
Sets the individual quaternion element at index to value. More... | |
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) |
Calculates Euler angles from a quaternion. More... | |
static Quaternion | componentWiseMultiply (Quaternion q1, Quaternion q2) |
Multiplies quaternion components component-wise and returns the resulting quaternion. More... | |
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) |
Divides each quaternion component with a scalar and returns the result. More... | |
static float | dotProduct (Quaternion q1, Quaternion q2) |
Calculates the dot product of two quaternions. More... | |
static long | getCPtr (Quaternion obj) |
static Quaternion | inverse (Quaternion q) |
Returns an inverse quaternion for a quaternion. More... | |
static Quaternion | matrix4x4ToQuaternion (Matrix4x4 matrix) |
Creates a quaternion from Matrix4x4. More... | |
static Quaternion | multiply (Quaternion q, float scalar) |
Multiplies each quaternion component with a scalar. More... | |
static Quaternion | multiply (Quaternion left, Quaternion right) |
Multiplies two quaternions. More... | |
static Quaternion | quaternionSlerp (Quaternion q1, Quaternion q2, float interpolationTime) |
Applies spherical linear interpolation (slerp) to two quaternions using the shortest path. More... | |
static Quaternion | quaternionSlerpLongerPath (Quaternion q1, Quaternion q2, float interpolationTime) |
Applies spherical linear interpolation (slerp) to two quaternion using the longer path. More... | |
static Matrix4x4 | quaternionToMatrix4x4 (Quaternion quaternion) |
Converts a quaternion rotation to a 4x4 rotation matrix. More... | |
static Vector3 | rotateVector (Quaternion quaternion, Vector3 vector) |
Applies quaternion rotation to a vector. More... | |
Protected Member Functions | |
void | finalize () |
Protected Attributes | |
transient boolean | swigCMemOwn |
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.
Quaternion | ( | float | x, |
float | y, | ||
float | z, | ||
float | w | ||
) |
Constructor, initializes the quaternion components to x, y, z and w.
x | x component of the quaternion. |
y | y component of the quaternion. |
z | z component of the quaternion. |
w | w component of the quaternion. |
|
static |
Calculates Euler angles from a quaternion.
Kanzi Engine represents Euler angles as Tait-Bryan angles where the rotations are applied in the order x, y, and z.
|
static |
Multiplies quaternion components component-wise and returns the resulting quaternion.
q1 | The first quaternion. |
q2 | The second quaternion. |
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.
|
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.
anglesInRadians | Euler angles in radians. |
|
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.
rotationX | Rotation angle around the x axis in radians. |
rotationY | Rotation angle around the y axis in radians. |
rotationZ | Rotation angle around the z axis in radians. |
|
static |
Creates quaternion from axis and angle.
Use this to create a quaternion from axis of rotation and angle in radians.
axis | Axis components in Vector3(x, y, z). |
angleInRadians | Angle in radians. |
|
static |
Divides each quaternion component with a scalar and returns the result.
q | Quaternion to divide. |
scalar | Divisor for each quaternion component. |
Quaternion divideByScalar | ( | float | scalar | ) |
Divides each quaternion component with a scalar and returns the result.
scalar | Divisor for each quaternion component. |
|
static |
Calculates the dot product of two quaternions.
q1 | The first quaternion. |
q2 | The second quaternion. |
float get | ( | long | index | ) |
Returns individual quaternion element value at index.
float getW | ( | ) |
Get the w component of the quaternion.
float getX | ( | ) |
Get the x component of the quaternion.
float getY | ( | ) |
Get the y component of the quaternion.
float getZ | ( | ) |
Get the z component of the quaternion.
|
static |
Returns an inverse quaternion for a quaternion.
q | Quaternion to invert. |
|
static |
Creates a quaternion from Matrix4x4.
Extracts and calculates the quaternion components from passed in Matrix4x4.
Use this when you already have the rotation stored in a 4x4 matrix and want to extract the rotation angles to a quaternion.
matrix | Matrix4x4 from which to extract and calculate the quaternion components. |
|
static |
Multiplies each quaternion component with a scalar.
q | Quaternion to multiply. |
scalar | Multiplier for each quaternion component. |
|
static |
Multiplies two quaternions.
You can combine a quaternion rotations by multiplying them:
rotating a vector v by quaternion q1 * q2 is the same as rotating the vector first by q2 and then by q1.
Quaternion multiplyByScalar | ( | float | scalar | ) |
Multiplies each quaternion component with a scalar.
scalar | Multiplier for each quaternion 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.
|
static |
Applies spherical linear interpolation (slerp) to two quaternions using the shortest path.
Use this to evaluate interpolation between two rotations at given interpolation time.
Takes the shortest path of interpolation between two degrees, which amounts to maximum of 180 degrees of rotation in any direction.
q1 | First quaternion. |
q2 | Second quaternion. |
interpolationTime | Interpolation parameter in range [0 .. 1]. |
|
static |
Applies spherical linear interpolation (slerp) to two quaternion using the longer path.
Use this to evaluate interpolation between two rotations at given interpolation time.
Takes the longer path to the result. Interpolates the whole angle difference between the two quaternion rotations. For example, from 0 to 270 rotates the whole 270 degrees.
q1 | First quaternion. |
q2 | Second quaternion. |
interpolationTime | Interpolation parameter in range [0 .. 1]. |
|
static |
Converts a quaternion rotation to a 4x4 rotation matrix.
quaternion | Quaternion rotation. |
|
static |
Applies quaternion rotation to a vector.
Calculates q * v * q.conjugated(), for a quaternion q and a vector v.
quaternion | Quaternion rotation. |
vector | Vector that you want to rotate. |
void set | ( | long | index, |
float | v | ||
) |
Sets the individual quaternion element at index to value.
index | Quaternion element index to set. |
void setW | ( | float | w | ) |
Sets the w component of the quaternion.
w | The new value of the w component. |
void setX | ( | float | x | ) |
Sets the x component of the quaternion.
x | The new value of the x component. |
void setY | ( | float | y | ) |
Sets the y component of the quaternion.
y | The new value of the y component. |
void setZ | ( | float | z | ) |
Sets the z component of the quaternion.
z | The new value of the z component. |