Zephyr Scientific Library (zscilib)
Modules | Files
Quaternions

Functions and structs for dealing with unit quaternions and orientation in 3D space. More...

Modules

 Structs, Enums and Macros
 Various structs, enums and macros related to quaternions.
 
 Initialisation
 Quaternion initisialisation.
 
 Functions
 Quaternion APIU functionsn.
 

Files

file  quaternions.h
 API header file for quaternions in zscilib.
 

Detailed Description

Functions and structs for dealing with unit quaternions and orientation in 3D space.

These functions deal largely with unit quaternions. Further work is required to support arbitrary quaternion math.

Quaternions can be thought of in one of three ways:

  1. As a vector with four components
  2. As a scalar (r) with a three component vector in right-hand ijk space (i, j, k)
  3. As a hypercomplex number consisting of a scalar real number (r), and three imaginary numbers (i, j, k)

When working with unit quaternions and orientation or rotation, we'll generally look at quaternions from the second point-of-view, as a scalar and three component vector in 3D space.

Note
The component parts of quaternions are sometimes referred to with a "w, x, y, z" notation instead of the "r, i, j, k" notation used in zscilib. The real number (r or w) may also be positioned after the imaginary numbers (xyzw or ijkr). The values are the same, but it's important to maintain consistent ordering. An optional 'alias' field is included in the zsl_quat struct if you prefer to use wxyz notation (q.alias.w == q.r, etc.).

With an extra degree of freedom compared to three-value Euler angles, quaternions provide a compact and efficient means of rotating or orienting vectors (x, y, z) in 3D space, similar to how vectors translate points (x, y) in 2D space.

They allow us to avoid a common problem with (otherwise more intuitive!) Euler angles called "gimbal lock".

Gimbal lock occurs when two axes in the Eular angle coincide after a rotation by a multiple of 90 degrees about the third axis, resulting in the loss of a degree of freedom. This leaves us with an unclear value for the logitude of the north or south poles, i.e. "which way is up?!?".

Quaternions also enable not just LINEAR interpolation (lerp) between two points (a and b) in normal space, but spherical linear interpolation (slerp) between two points in a sphere, travelling across the surface of the sphere rather than in a straight line. This enables us to interpolate between arbitrary orientations (x, y, z), not just arbitrary points (x, y).