Kanzi  3.9.5
Kanzi Engine API
kanzi::Quaternion Class Reference

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

#include <kanzi/core/math/quaternion.hpp>

Inheritance diagram for kanzi::Quaternion:
[legend]

Public Member Functions

Quaternion conjugated () const
 Get conjugated copy of this quaternion. More...
 
float getW () const
 Get the w component of the quaternion. More...
 
float getX () const
 Get the x component of the quaternion. More...
 
float getY () const
 Get the y component of the quaternion. More...
 
float getZ () const
 Get the z component of the quaternion. More...
 
KZ_NO_DISCARD Quaternion normalized () const
 Get normalized copy of this quaternion. More...
 
Quaternion operator* (float scalar) const
 Multiplies each quaternion component with a scalar and returns the result. More...
 
Quaternionoperator*= (float scalar)
 Multiplies each quaternion component with a scalar. More...
 
Quaternion operator/ (float scalar) const
 Divides each quaternion component with a scalar and returns the result. More...
 
Quaternionoperator/= (float scalar)
 Divides each quaternion component with a scalar. More...
 
float & operator[] (size_t index)
 Access individual components of a quaternion. More...
 
const float & operator[] (size_t index) const
 Access individual components of a quaternion. More...
 
 Quaternion ()
 Default constructor, initializes the quaternion components to identity, representing no rotation (x=0, y=0, z=0, w=1). More...
 
 Quaternion (const float x, const float y, const float z, const float w)
 Constructor, initializes the quaternion components to x, y, z and w. 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 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...
 

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 also
operator*().
rotateVector().

Constructor & Destructor Documentation

◆ Quaternion() [1/2]

kanzi::Quaternion::Quaternion ( )
inlineexplicit

Default constructor, initializes the quaternion components to identity, representing no rotation (x=0, y=0, z=0, w=1).

◆ Quaternion() [2/2]

kanzi::Quaternion::Quaternion ( const float  x,
const float  y,
const float  z,
const float  w 
)
inlineexplicit

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

◆ createFromVector()

static Quaternion kanzi::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.

◆ createFromEulerAngles() [1/2]

static Quaternion kanzi::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.

◆ createFromEulerAngles() [2/2]

static Quaternion kanzi::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.

◆ normalized()

KZ_NO_DISCARD Quaternion kanzi::Quaternion::normalized ( ) const

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.

◆ conjugated()

Quaternion kanzi::Quaternion::conjugated ( ) const
inline

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.

◆ getX()

float kanzi::Quaternion::getX ( ) const
inline

Get the x component of the quaternion.

Returns
The x component.

◆ getY()

float kanzi::Quaternion::getY ( ) const
inline

Get the y component of the quaternion.

Returns
The y component.

◆ getZ()

float kanzi::Quaternion::getZ ( ) const
inline

Get the z component of the quaternion.

Returns
The z component.

◆ getW()

float kanzi::Quaternion::getW ( ) const
inline

Get the w component of the quaternion.

Returns
The w component.

◆ setX()

void kanzi::Quaternion::setX ( float  x)
inline

Sets the x component of the quaternion.

Parameters
xThe new value of the x component.

◆ setY()

void kanzi::Quaternion::setY ( float  y)
inline

Sets the y component of the quaternion.

Parameters
yThe new value of the y component.

◆ setZ()

void kanzi::Quaternion::setZ ( float  z)
inline

Sets the z component of the quaternion.

Parameters
zThe new value of the z component.

◆ setW()

void kanzi::Quaternion::setW ( float  w)
inline

Sets the w component of the quaternion.

Parameters
wThe new value of the w component.

◆ operator[]() [1/2]

float& kanzi::Quaternion::operator[] ( size_t  index)
inline

Access individual components of a quaternion.

Parameters
indexIndex of the accessed component. Should be either 0, 1, 2, or 3.
Returns
If index is 0, x component. If index is 1, y component. If index is 2, z component. If index is 3, w component.

◆ operator[]() [2/2]

const float& kanzi::Quaternion::operator[] ( size_t  index) const
inline

Access individual components of a quaternion.

Parameters
indexIndex of the accessed component. Should be either 0, 1, 2, or 3.
Returns
If index is 0, x component. If index is 1, y component. If index is 2, z component. If index is 3, w component.

◆ operator*()

Quaternion kanzi::Quaternion::operator* ( float  scalar) const
inline

Multiplies each quaternion component with a scalar and returns the result.

Parameters
scalarMultiplier for each quaternion component.
Returns
Result quaternion.

◆ operator*=()

Quaternion& kanzi::Quaternion::operator*= ( float  scalar)
inline

Multiplies each quaternion component with a scalar.

Parameters
scalarMultiplier for each quaternion component.
Returns
This quaternion.

◆ operator/()

Quaternion kanzi::Quaternion::operator/ ( float  scalar) const
inline

Divides each quaternion component with a scalar and returns the result.

Parameters
scalarDivisor for each quaternion component.
Returns
Result quaternion.

◆ operator/=()

Quaternion& kanzi::Quaternion::operator/= ( float  scalar)
inline

Divides each quaternion component with a scalar.

Parameters
scalarDivisor for each quaternion component.
Returns
This quaternion.

The documentation for this class was generated from the following file: