Quaternions represent rotation around an axis, defined by quaternion components x, y, z and w.
More...
#include <kanzi/core/math/quaternion.hpp>
|
Quaternion | conjugated () const |
| Get conjugated copy of this quaternion.
|
|
float | getW () const |
| Get the w component of the quaternion.
|
|
float | getX () const |
| Get the x component of the quaternion.
|
|
float | getY () const |
| Get the y component of the quaternion.
|
|
float | getZ () const |
| Get the z component of the quaternion.
|
|
KZ_NO_DISCARD Quaternion | normalized () const |
| Get normalized copy of this quaternion.
|
|
Quaternion | operator* (float scalar) const |
| Multiplies each quaternion component with a scalar and returns the result.
|
|
Quaternion & | operator*= (float scalar) |
| Multiplies each quaternion component with a scalar.
|
|
Quaternion | operator/ (float scalar) const |
| Divides each quaternion component with a scalar and returns the result.
|
|
Quaternion & | operator/= (float scalar) |
| Divides each quaternion component with a scalar.
|
|
float & | operator[] (size_t index) |
| Access individual components of a quaternion.
|
|
const float & | operator[] (size_t index) const |
| Access individual components of a quaternion.
|
|
| 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.
|
|
void | setW (float w) |
| Sets the w component of the quaternion.
|
|
void | setX (float x) |
| Sets the x component of the quaternion.
|
|
void | setY (float y) |
| Sets the y component of the quaternion.
|
|
void | setZ (float z) |
| Sets the z component of the quaternion.
|
|
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().
◆ 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]
Constructor, initializes the quaternion components to x, y, z and w.
- Parameters
-
x | x component of the quaternion. |
y | y component of the quaternion. |
z | z component of the quaternion. |
w | w component of the quaternion. |
◆ createFromVector()
Creates quaternion from axis and angle.
Use this to create a quaternion from axis of rotation and angle in radians.
- Parameters
-
axis | Axis components in Vector3(x, y, z). |
angleInRadians | Angle in radians. |
- Returns
- Rotated quaternion.
◆ createFromEulerAngles() [1/2]
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
-
anglesInRadians | Euler angles in radians. |
- Returns
- Rotated quaternion.
◆ createFromEulerAngles() [2/2]
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
-
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. |
- Returns
- Rotated 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.
◆ 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()
Sets the x component of the quaternion.
- Parameters
-
x | The new value of the x component. |
◆ setY()
Sets the y component of the quaternion.
- Parameters
-
y | The new value of the y component. |
◆ setZ()
Sets the z component of the quaternion.
- Parameters
-
z | The new value of the z component. |
◆ setW()
Sets the w component of the quaternion.
- Parameters
-
w | The new value of the w component. |
◆ operator[]() [1/2]
float & kanzi::Quaternion::operator[] |
( |
size_t | index | ) |
|
|
inline |
Access individual components of a quaternion.
- Parameters
-
index | Index 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
-
index | Index 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*()
Multiplies each quaternion component with a scalar and returns the result.
- Parameters
-
scalar | Multiplier for each quaternion component. |
- Returns
- Result quaternion.
◆ operator*=()
Multiplies each quaternion component with a scalar.
- Parameters
-
scalar | Multiplier for each quaternion component. |
- Returns
- This quaternion.
◆ operator/()
Divides each quaternion component with a scalar and returns the result.
- Parameters
-
scalar | Divisor for each quaternion component. |
- Returns
- Result quaternion.
◆ operator/=()
Divides each quaternion component with a scalar.
- Parameters
-
scalar | Divisor for each quaternion component. |
- Returns
- This quaternion.
The documentation for this class was generated from the following file: