Next: , Previous: , Up: Math   [Contents][Index]


4.2.5 Quaternions

(use-modules (sly math quaternion))

Quaternions are used to express rotations about an arbitrary axis in a way that avoids “gimbal lock” and allows for useful interpolation, unlike matrices or Euler angles.

Quaternions can be used in rotation transformations (see Transforms), as well as converted to and from Vectors.

Record Type: <quaternion>

Data type with 4 fields: w, x, y, z, in that order. This type descriptor has been exposed for destructuring via Guile’s (ice-9 match) module.

Scheme Procedure: make-quaternion v theta
Scheme Procedure: make-quaternion w x y z

Create a new quaternion from an axis angle (a 3D vector v plus an angle theta) or from individual coordinates w, x, y, and z.

Scheme Procedure: quaternion v theta
Scheme Procedure: quaternion w x y z

Alternate spelling of make-quaternion.

Scheme Syntax: quaternion? obj

Return #t if obj is a quaternion.

Scheme Syntax: quaternion-w q

Return the w coordinate of the quaternion q.

Scheme Syntax: quaternion-x q

Return the x coordinate of the quaternion q.

Scheme Syntax: quaternion-y q

Return the y coordinate of the quaternion q.

Scheme Syntax: quaternion-z q

Return the z coordinate of the quaternion q.

Scheme Variable: identity-quaternion

The multiplicative identity quaternion.

Scheme Variable: null-quaternion

A quaternion with all fields set to zero.

Scheme Procedure: quaternion* . quaternions

Return the product of all quaternions. Return identity-quaternion if called without arguments.

Scheme Procedure: quaternion-slerp q1 q2 delta

Perform a spherical linear interpolation of the quaternions q1 and q2 and blending factor delta.

Scheme Procedure: quaternion-magnitude q

Return the magnitude of the quaternion q.

Scheme Procedure: quaternion-normalize q

Return the normalized form of the quaternion q.

Scheme Procedure: vector->quaternion v

Convert the 4D vector v to a quaternion.

Scheme Procedure: quaternion->vector q

Convert the quaternion q to a 4D vector.


Next: , Previous: , Up: Math   [Contents][Index]