Library quaternion

Quaternion library.

Functions

New( ... ) Creates a new Quaternion given a variety of inputs
abs( q ) Returns the absolute value of q.
conj( q ) Returns the conjugate of q.
exp( q ) Returns Euler's constant e raised to the power q.
fromAngles( angles ) Creates a quaternion representing the given angles.
fromAxis( forward, up ) Creates a quaternion representing the angles expressed by the given basis vectors.
fromComponents( real, i, j, k ) Creates a quaternion from the given components.
fromEntity( entity ) Creates a quaternion representing the angles of the given entity.
fromNumber( real ) Creates a quaternion with real part equal to the given number.
fromNumberAndVector( real, imaginaryParts ) Creates a quaternion whose real part is the given number, and whose imaginary parts are taken from the given vector.
fromVector( imaginaryParts ) Creates a quaternion with imaginary parts set from the given vector.
inv( q ) Returns the inverse of q.
log( q ) Returns the natural logarithm of q.
qMod( q ) Changes quaternion q so that the represented rotation is by an angle between 0 and 180 degrees.
qRotation( rotVec ) Constructs a quaternion from the rotation vector rotVec.
qRotationAxis( axis, ang ) Returns a quaternion for rotation about the given axis by the given angle.
qi( n ) Returns Quaternion n * i
qj( n ) Returns Quaternion n * j
qk( n ) Returns Quaternion n * k
rotationAngle( q ) Returns the angle of rotation in degrees.
rotationAxis( q ) Returns the axis of rotation.
rotationVector( q ) Returns the rotation vector represented by the given quaternion, where the magnitude is the angle of rotation in degress.
slerp( q0, q1, t ) Performs spherical interpolation between q0 and q1.
vec( q ) Converts q to a vector by dropping the real component.


Functions

quaternion.New( ... )
Creates a new Quaternion given a variety of inputs

Environment:

Shared

Parameters:

  • ...: A series of arguments which lead to valid generation of a quaternion. Acceptable inputs are: - A single number for the real part. - 4 numbers for the real and 3 imaginary parts. - A vector which populates the imaginary parts. - An angle object. - A number and a vector to populate the real and imaginary parts. - 2 vectors to populate with the angle of the cross product between them. - An entity which populates using the entity's angles.

Return value:

    (Quaternion) A new quaternion whose values depend on the provided input.
quaternion.abs( q )
Returns the absolute value of q.

Environment:

Shared

Parameters:

  • q: The quaternion to get the absolute value of.

Return value:

    (number) The absolute value of the given quaternion.
quaternion.conj( q )
Returns the conjugate of q.

Environment:

Shared

Parameters:

  • q: The quaternion to get the conjugate of.

Return value:

    (Quaternion) The conjugate of the given quaternion.
quaternion.exp( q )
Returns Euler's constant e raised to the power q.

Environment:

Shared

Parameters:

  • q: The quaternion to raise e to the power of.

Return value:

    (Quaternion) e raised to the power of the given quaternion.
quaternion.fromAngles( angles )
Creates a quaternion representing the given angles.

Environment:

Shared

Parameters:

  • angles: The angles to represent.

Return value:

    (Quaternion) A quaternion representing the given angles.
quaternion.fromAxis( forward, up )
Creates a quaternion representing the angles expressed by the given basis vectors.

Environment:

Shared

Parameters:

  • forward: The forward direction of the basis.
  • up: The up direction of the basis.

Return value:

    (Quaternion) A quaternion representing the world angles of the basis' forward direction, accounting for roll.
quaternion.fromComponents( real, i, j, k )
Creates a quaternion from the given components.

Environment:

Shared

Parameters:

  • real: The real part.
  • i: The i component.
  • j: The j component.
  • k: The k component.

Return value:

    (Quaternion) A quaternion with the given components.
quaternion.fromEntity( entity )
Creates a quaternion representing the angles of the given entity.

Environment:

Shared

Parameters:

  • entity: The entity whose angles should be used.

Return value:

    (Quaternion) A quaternion representing the angles of the given entity.
quaternion.fromNumber( real )
Creates a quaternion with real part equal to the given number.

Environment:

Shared

Parameters:

  • real: The real part.

Return value:

    (Quaternion) A quaternion whose real part is equal to the given value, with no imaginary parts.
quaternion.fromNumberAndVector( real, imaginaryParts )
Creates a quaternion whose real part is the given number, and whose imaginary parts are taken from the given vector.

Environment:

Shared

Parameters:

  • real: The real part.
  • imaginaryParts: The imaginary parts as a Vector.

Return value:

    (Quaternion) A quaternion whose real part is the given number, and imginary parts are taken from the given vector (i, j, k).
quaternion.fromVector( imaginaryParts )
Creates a quaternion with imaginary parts set from the given vector.

Environment:

Shared

Parameters:

  • imaginaryParts: The imaginary parts as a Vector.

Return value:

    (Quaternion) A quaternion whose real part is 0, and imginary parts are taken from the given vector (i, j, k).
quaternion.inv( q )
Returns the inverse of q.

Environment:

Shared

Parameters:

  • q: The quaternion to get the inverse of.

Return value:

    (Quaternion) The inverse of the given quaternion.
quaternion.log( q )
Returns the natural logarithm of q.

Environment:

Shared

Parameters:

  • q: The quaternion to apply the natural logarithm to.

Return value:

    (Quaternion) The natural logarithm of the given quaternion.
quaternion.qMod( q )
Changes quaternion q so that the represented rotation is by an angle between 0 and 180 degrees.

Environment:

Shared

Parameters:

  • q: The quaternion to normalise.

Return value:

    (Quaternion) A new quaternion with a normalised angle.
quaternion.qRotation( rotVec )
Constructs a quaternion from the rotation vector rotVec. Vector direction is axis of rotation, magnitude is angle in degrees.

Environment:

Shared

Parameters:

  • rotVec: The rotation vector to be represented as a quaternion.

Return value:

    (Quaternion) A quaternion that, when applied to a vector, rotates it by the given direction and magnitude in degrees.
quaternion.qRotationAxis( axis, ang )
Returns a quaternion for rotation about the given axis by the given angle.

Environment:

Shared

Parameters:

  • axis: The axis of rotation.
  • ang: The magntidue of rotation (in degrees).

Return value:

    (Quaternion) A quaternion that, when applied to a vector, rotates it around the given axis by the given angle in degrees.
quaternion.qi( n )
Returns Quaternion n * i

Environment:

Shared

Parameters:

  • n: The value of the i component.

Return value:

    (Quaternion) A quaternion whose i component is n and all others are 0.
quaternion.qj( n )
Returns Quaternion n * j

Environment:

Shared

Parameters:

  • n: The value of the j component.

Return value:

    (Quaternion) A quaternion whose j component is n and all others are 0.
quaternion.qk( n )
Returns Quaternion n * k

Environment:

Shared

Parameters:

  • n: The value of the k component.

Return value:

    (Quaternion) A quaternion whose k component is n and all others are 0.
quaternion.rotationAngle( q )
Returns the angle of rotation in degrees.

Environment:

Shared

Parameters:

  • q: The quaternion to extract the rotation angle from.

Return value:

    (number) The angle of rotation represented by the given quaternion, in degrees.
quaternion.rotationAxis( q )
Returns the axis of rotation.

Environment:

Shared

Parameters:

  • q: The quaternion to extract the rotation axis from.

Return value:

    (Vector) The axis of rotation.
quaternion.rotationVector( q )
Returns the rotation vector represented by the given quaternion, where the magnitude is the angle of rotation in degress.

Environment:

Shared

Parameters:

  • q: The quaternion to extract the rotation vector from.

Return value:

    (Vector) A vector representing the rotation vector of the given quaternion.
quaternion.slerp( q0, q1, t )
Performs spherical interpolation between q0 and q1. Returns q0 for t = 0, q1 for t = 1.

Environment:

Shared

Parameters:

  • q0: The starting quaternion.
  • q1: The target quaternion.
  • t: The fraction between the 2 quaternions (between 0 and 1).

Return value:

    (Quaternion) A quaternion that is between q0 and q1, spherically interpolated based on the value of t.
quaternion.vec( q )
Converts q to a vector by dropping the real component.

Environment:

Shared

Parameters:

  • q: The quaternion to extract the imaginary parts from.

Return value:

    (Vector) A vector whose components are the i, j, k components of the quaternion.

Valid XHTML 1.0!