Skip to content

quaternion overview


Table of contents


utils

Qtrn (class)

Helper class with static functions, containing util functions, related to Quaternion (represented as Point4 type). In terms of rotation, a quaternion is a mathematical representation of an orientation or rotation in 3D space. It consists of a scalar component and a vector component, and can be written as q = w + xi + yj + zk, where w is the scalar component, and i, j, and k are the vector components. The scalar component, w, represents the amount of rotation, and the vector component, (x, y, z), represents the axis of rotation. The length of the vector component represents the amount of rotation around the axis. Quaternions are often used in 3D computer graphics and animation because they can be used to interpolate between two rotations, and they can avoid some of the issues with using Euler angles (such as gimbal lock).

Signature

export declare class Qtrn

clone (static method)

Returns a new quaternion instance with the same values as the given quaternion object.

Signature

static clone(q: Point4): Point4

spr (static method)

spread quaternion components

Signature

static spr(p: Point4): [number, number, number, number]

add (static method)

Returns the sum of two Point4 objects.

Signature

static add(a: Point4, b: Point4): Point4

mult (static method)

Returns the result of multiplying two Point4 objects. This can be used for combining rotations

Signature

static mult(a: Point4, b: Point4): Point4

conjugate (static method)

Calculates and returns the conjugate of a quaternion. The conjugate of a quaternion is obtained by changing the sign of its vector components.

Signature

static conjugate(q: Point4): Point4

opposite (static method)

Returns the opposite of a quaternion. It's obtained by negating all quaternion elements(x, y, z and w).

Signature

static opposite(q: Point4): Point4

combineRotations (static method)

Combines an arbitrary number of quaternions by multiplying them together in order.

Signature

static combineRotations(...quaternions: Point4[]): Point4

lerp (static method)

Performs a linear interpolation between two Point4 objects.

Signature

static lerp(a: Point4, b: Point4, t: number): Point4

slerp (static method)

Performs a spherical linear interpolation between two Point4 objects.

Signature

static slerp(a: Point4, b: Point4, t: number): Point4

fromAngle (static method)

Converts an angle and an axis of rotation into a quaternion

Signature

static fromAngle(axis: Point3, angle: number)

fromMatrix4 (static method)

Converts a 4x4 matrix representing a rotation into a quaternion

Signature

static fromMatrix4(m: number[]): Point4

fromMatrix3 (static method)

Converts a 3x3 rotation matrix into a quaternion

Signature

static fromMatrix3(m: number[][]): Point4

fromEuler (static method)

Creates a quaternion from euler

Signature

static fromEuler(e: Point3): Point4

toEuler (static method)

Converts a quaternion to euler

Signature

static toEuler(q: Point4): Point3

lookAt (static method)

Returns a quaternion that represents the rotation required to align an object to face towards a target point.

Signature

static lookAt(eye: Point3, target: Point3, up: Point3 = Pnt3.Z): Point4

rotAround (static method)

Returns a quaternion that represents the input quaternion, rotated around provided axis vector by provided angle. Assumes that axis vector is already normalized

Signature

static rotAround(q: Point4, axis: Point3, angle: number): Point4