Home Reference Source
import {Quaternion} from 'math-ds'
public class | source

Quaternion

A quaternion.

Static Method Summary

Static Public Methods
public static

Performs a spherical linear interpolation.

public static

slerpFlat(dst: Number[], dstOffset: Number, src0: Number[], srcOffset0: Number, src1: Number[], srcOffset1: Number, t: Number)

Performs an array-based spherical linear interpolation.

Constructor Summary

Public Constructor
public

Constructs a new quaternion.

Member Summary

Public Members
public

The W component.

public

The X component.

public

The Y component.

public

The Z component.

Method Summary

Public Methods
public

Calculates the angle to another quaternion.

public

Clones this quaternion.

public

Conjugates this quaternion.

public

Copies the components of the given quaternion.

public

Calculates the dot product with a given vector.

public

Checks if this quaternions equals the given one.

public

fromArray(array: Number[], offset: Number): Quaternion

Copies values from an array.

public

Inverts this quaternion.

public

Calculates the length of this quaternion.

public

Calculates the squared length of this quaternion.

public

Multiplies this quaternion with the given one and stores the result in this quaternion.

public

Multiplies the given quaternions and stores the result in this quaternion.

public

Normalizes this quaternion.

public

Multiplies the given quaternion with this one and stores the result in this quaternion.

public

Rotates this quaternion towards the given one by a given step size.

public

Sets the components of this quaternion.

public

Sets the components of this quaternion based on a given axis angle.

public

Sets the components of this quaternion based on the given Euler angles.

public

Sets the components of this quaternion based on a given rotation matrix.

public

Sets the components of this quaternion based on unit vectors.

public

Performs a spherical linear interpolation towards the given quaternion.

public

toArray(array: Array, offset: Number): Number[]

Stores this quaternion in an array.

Static Public Methods

public static slerp(qa: Quaternion, qb: Quaternion, qr: Quaternion, t: Number): Quaternion source

Performs a spherical linear interpolation.

Params:

NameTypeAttributeDescription
qa Quaternion

The base quaternion.

qb Quaternion

The target quaternion.

qr Quaternion

A quaternion to store the result in.

t Number

The slerp factor.

Return:

Quaternion

The resulting quaternion.

public static slerpFlat(dst: Number[], dstOffset: Number, src0: Number[], srcOffset0: Number, src1: Number[], srcOffset1: Number, t: Number) source

Performs an array-based spherical linear interpolation.

Params:

NameTypeAttributeDescription
dst Number[]

An array to store the result in.

dstOffset Number

An offset into the destination array.

src0 Number[]

An array that contains the base quaternion values.

srcOffset0 Number

An offset into the base array.

src1 Number[]

An array that contains the target quaternion values.

srcOffset1 Number

An offset into the target array.

t Number

The slerp factor.

Public Constructors

public constructor(x: Number, y: Number, z: Number, w: Number) source

Constructs a new quaternion.

Params:

NameTypeAttributeDescription
x Number
  • optional
  • default: 0

The X component.

y Number
  • optional
  • default: 0

The Y component.

z Number
  • optional
  • default: 0

The Z component.

w Number
  • optional
  • default: 0

The W component.

Public Members

public w: Number source

The W component.

public x: Number source

The X component.

public y: Number source

The Y component.

public z: Number source

The Z component.

Public Methods

public angleTo(q: Quaternion): Number source

Calculates the angle to another quaternion.

Params:

NameTypeAttributeDescription
q Quaternion

A quaternion.

Return:

Number

The angle in radians.

public clone(): Quaternion source

Clones this quaternion.

Return:

Quaternion

The cloned quaternion.

public conjugate(): Quaternion source

Conjugates this quaternion.

Return:

Quaternion

This quaternion.

public copy(q: Quaternion): Quaternion source

Copies the components of the given quaternion.

Params:

NameTypeAttributeDescription
q Quaternion

The quaternion.

Return:

Quaternion

This quaternion.

public dot(v: Vector4): Number source

Calculates the dot product with a given vector.

Params:

NameTypeAttributeDescription
v Vector4

A vector.

Return:

Number

The dot product.

public equals(q: Quaternion): Boolean source

Checks if this quaternions equals the given one.

Params:

NameTypeAttributeDescription
q Quaternion

A quaternion.

Return:

Boolean

Whether the quaternions are equal.

public fromArray(array: Number[], offset: Number): Quaternion source

Copies values from an array.

Params:

NameTypeAttributeDescription
array Number[]

An array.

offset Number

An offset.

Return:

Quaternion

This quaternion.

public invert(): Quaternion source

Inverts this quaternion. The quaternion is assumed to have unit length.

Return:

Quaternion

This quaternion.

public length(): Number source

Calculates the length of this quaternion.

Return:

Number

The length.

public lengthSquared(): Number source

Calculates the squared length of this quaternion.

Return:

Number

The squared length.

public multiply(q: Quaternion): Quaternion source

Multiplies this quaternion with the given one and stores the result in this quaternion.

Params:

NameTypeAttributeDescription
q Quaternion

A quaternion.

Return:

Quaternion

This quaternion.

public multiplyQuaternions(a: Quaternion, b: Quaternion): Quaternion source

Multiplies the given quaternions and stores the result in this quaternion.

For more details see: http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm

Params:

NameTypeAttributeDescription
a Quaternion

A quaternion.

b Quaternion

Another quaternion.

Return:

Quaternion

This quaternion.

public normalize(): Quaternion source

Normalizes this quaternion.

Return:

Quaternion

This quaternion.

public premultiply(q: Quaternion): Quaternion source

Multiplies the given quaternion with this one and stores the result in this quaternion.

Params:

NameTypeAttributeDescription
q Quaternion

A quaternion.

Return:

Quaternion

This quaternion.

public rotateTowards(q: Quaternion, step: Number): Quaternion source

Rotates this quaternion towards the given one by a given step size.

Params:

NameTypeAttributeDescription
q Quaternion

The target quaternion.

step Number

The step size.

Return:

Quaternion

This quaternion.

public set(x: Number, y: Number, z: Number, w: Number): Quaternion source

Sets the components of this quaternion.

Params:

NameTypeAttributeDescription
x Number

The X component.

y Number

The Y component.

z Number

The Z component.

w Number

The W component.

Return:

Quaternion

This quaternion.

public setFromAxisAngle(axis: Vector3, angle: Number): Quaternion source

Sets the components of this quaternion based on a given axis angle.

For more information see: http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm

Params:

NameTypeAttributeDescription
axis Vector3

The axis. Assumed to be normalized.

angle Number

The angle in radians.

Return:

Quaternion

This quaternion.

public setFromEuler(euler: Euler): Quaternion source

Sets the components of this quaternion based on the given Euler angles.

For more details see: https://goo.gl/XRD1kr

Params:

NameTypeAttributeDescription
euler Euler

The euler angles.

Return:

Quaternion

This quaternion.

public setFromRotationMatrix(m: Matrix4): Quaternion source

Sets the components of this quaternion based on a given rotation matrix.

For more information see: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm

Params:

NameTypeAttributeDescription
m Matrix4

The rotation matrix. The upper 3x3 is assumed to be a pure rotation matrix (i.e. unscaled).

Return:

Quaternion

This quaternion.

public setFromUnitVectors(vFrom: Vector3, vTo: Vector3): Quaternion source

Sets the components of this quaternion based on unit vectors.

Params:

NameTypeAttributeDescription
vFrom Vector3

A unit vector. Assumed to be normalized.

vTo Vector3

A unit vector. Assumed to be normalized.

Return:

Quaternion

This quaternion.

public slerp(q: Quaternion, t: Number): Quaternion source

Performs a spherical linear interpolation towards the given quaternion.

For more details see: http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/

Params:

NameTypeAttributeDescription
q Quaternion

A quaternion.

t Number

The slerp factor.

Return:

Quaternion

This quaternion.

public toArray(array: Array, offset: Number): Number[] source

Stores this quaternion in an array.

Params:

NameTypeAttributeDescription
array Array
  • optional

A target array.

offset Number

An offset.

Return:

Number[]

The array.