Implementation of a quaternion. Quaternions are used to represent rotations.

Example

const quaternion = new Quaternion();
quaternion.setFromAxisAngle( new Vector3( 0, 1, 0 ), Math.PI / 2 );

const vector = new Vector3( 1, 0, 0 );
vector.applyQuaternion( quaternion );

Hierarchy

  • Base
    • Quaternion

Constructors

  • new Quaternion(x?: number, y?: number, z?: number, w?: number): Quaternion
  • Create a new instance. Default is a unit quaternion

    Parameters

    • x: number = 0

      x coordinate

    • y: number = 0

      y coordinate

    • z: number = 0

      z coordinate

    • w: number = 1

      w coordinate

    Returns Quaternion

Properties

_w: number
_x: number
_y: number
_z: number

Accessors

  • get isBox2(): boolean
  • Returns boolean

  • get isBox3(): boolean
  • Returns boolean

  • get isColor(): boolean
  • Returns boolean

  • get isCylindrical(): boolean
  • Returns boolean

  • get isEuler(): boolean
  • Returns boolean

  • get isLine3(): boolean
  • Returns boolean

  • get isMatrix3(): boolean
  • Returns boolean

  • get isMatrix4(): boolean
  • Returns boolean

  • get isPlane(): boolean
  • Returns boolean

  • get isQuaternion(): boolean
  • Read-only flag to check if a given object is of type Quaternion.

    Returns boolean

  • get isRay(): boolean
  • Returns boolean

  • get isSphere(): boolean
  • Returns boolean

  • get isSpherical(): boolean
  • Returns boolean

  • get isTriangle(): boolean
  • Returns boolean

  • get isVector2(): boolean
  • Returns boolean

  • get isVector3(): boolean
  • Returns boolean

  • get isVector4(): boolean
  • Returns boolean

  • get w(): number
  • set w(value: number): void
  • Returns number

  • Parameters

    • value: number

    Returns void

  • get x(): number
  • set x(value: number): void
  • Returns number

  • Parameters

    • value: number

    Returns void

  • get y(): number
  • set y(value: number): void
  • Returns number

  • Parameters

    • value: number

    Returns void

  • get z(): number
  • set z(value: number): void
  • Returns number

  • Parameters

    • value: number

    Returns void

Methods

  • [iterator](): IterableIterator<number>
  • Returns IterableIterator<number>

  • Parameters

    • callback: (() => void)
        • (): void
        • Returns void

    Returns Quaternion

  • _onChangeCallback(): void
  • Returns void

  • Find the angle between this quaternion and quaternion q in radians.

    Returns

    The angle.

    Parameters

    Returns number

  • Creates a new Quaternion with identical x, y, z and w properties to this one.

    Returns

    A new instance.

    Returns Quaternion

  • Compute the rotational conjugate of this quaternion. The conjugate of a quaternion represents the same rotation in the opposite direction about the rotational axis.

    Returns

    The conjugate quaternion.

    Returns Quaternion

  • Copies the x, y, z and w properties of q into this quaternion.

    Returns

    This instance.

    Parameters

    Returns Quaternion

  • Calculates the dot product of quaternions v and this one.

    Returns

    The dot product.

    Parameters

    Returns number

  • Compares the x, y, z and w properties of v to the equivalent properties of this quaternion to determine if they represent the same rotation.

    Returns

    True when equivalance is found; false otherwise.

    Parameters

    • quaternion: Quaternion

      quaternion that this quaternion will be compared to.

    Returns boolean

  • fromArray(array: number[], offset??: number): Quaternion
  • Sets this quaternion's x, y, z and w properties from an array.

    Returns

    This instance.

    Parameters

    • array: number[]

      array of format (x, y, z, w) used to construct the quaternion.

    • Optional offset: number = 0

      an offset into the array.

    Returns Quaternion

  • Sets this quaternion to the identity quaternion; that is, to the quaternion that represents "no rotation".

    Returns

    This instance

    Returns Quaternion

  • Inverts this quaternion - calculates the conjugate. The quaternion is assumed to have unit length.

    Returns

    This instance.

    Returns Quaternion

  • length(): number
  • Computes the Euclidean length (straight-line length) of this quaternion, considered as a 4 dimensional vector.

    Returns

    The Euclidean length.

    Returns number

  • lengthSq(): number
  • Computes the squared Euclidean length (straight-line length) of this quaternion, considered as a 4 dimensional vector. This can be useful if you are comparing the lengths of two quaternions, as this is a slightly more efficient calculation than length().

    Returns

    The squared Euclidean length.

    Returns number

  • Normalizes this quaternion - that is, calculated the quaternion that performs the same rotation as this one, but has length equal to 1.

    Returns

    This instance.

    Returns Quaternion

  • Pre-multiplies this quaternion by q.

    Returns

    This instance.

    Parameters

    Returns Quaternion

  • Sets this quaternion to a uniformly random, normalized quaternion.

    Returns

    This instance.

    Returns Quaternion

  • Rotates this quaternion by a given angular step to the defined quaternion q. The method ensures that the final quaternion will not overshoot q.

    Returns

    This instance.

    Parameters

    • q: Quaternion

      THe target quaternion

    • step: number

      The angular step in radians

    Returns Quaternion

  • set(x: number, y: number, z: number, w: number): Quaternion
  • Sets x, y, z, w properties of this quaternion.

    Returns

    This instance.

    Parameters

    • x: number
    • y: number
    • z: number
    • w: number

    Returns Quaternion

  • Sets this quaternion from the rotation specified by Euler angle.

    Returns

    This instance.

    Parameters

    • euler: Euler
    • Optional update: boolean

    Returns Quaternion

  • Sets this quaternion from rotation component of m.

    Returns

    This instance.

    Parameters

    • m: Matrix4

      a Matrix4 of which the upper 3x3 of matrix is a pure rotation matrix (i.e. unscaled).

    Returns Quaternion

  • Sets this quaternion to the rotation required to rotate direction vector vFrom to direction vector vTo.

    Returns

    This instance.

    Parameters

    Returns Quaternion

  • Handles the spherical linear interpolation between quaternions. t represents the amount of rotation between this quaternion (where t is 0) and qb (where t is 1). This quaternion is set to the result. Also see the static version of the slerp below.

    Returns

    This instance.

    Parameters

    • qb: Quaternion

      The other quaternion rotation

    • t: number

      interpolation factor in the closed interval [0, 1].

    Returns Quaternion

  • Performs a spherical linear interpolation between the given quaternions and stores the result in this quaternion.

    Returns

    This instance.

    Parameters

    Returns Quaternion

  • toArray(array?: number[], offset?: number): number[]
  • Calculates the numerical elements of this quaternion in an array of format [x, y, z, w].

    Returns

    The array equivalent of this quaternion.

    Parameters

    • array: number[] = []

      An optional array to store the quaternion. If not specified, a new array will be created.

    • offset: number = 0

      if specified, the result will be copied into this Array.

    Returns number[]

  • multiplyQuaternionsFlat(dst: number[], dstOffset: number, src0: number[], srcOffset0: number, src1: number[], srcOffset1: number): number[]
  • Multiply 2 quaterions. This multiplication implementation assumes the quaternion data are managed in flat arrays.

    Parameters

    • dst: number[]

      The output array.

    • dstOffset: number

      An offset into the output array.

    • src0: number[]

      The source array of the starting quaternion.

    • srcOffset0: number

      An offset into the array src0.

    • src1: number[]

      The source array of the target quaternion.

    • srcOffset1: number

      An offset into the array src1.

    Returns number[]

  • slerpFlat(dst: number[], dstOffset: number, src0: number[], srcOffset0: number, src1: number[], srcOffset1: number, t: number): void
  • This SLERP implementation assumes the quaternion data are managed in flat arrays.

    Parameters

    • dst: number[]
    • dstOffset: number

      An offset into the output array.

    • src0: number[]

      The source array of the starting quaternion.

    • srcOffset0: number

      An offset into the array src0.

    • src1: number[]

      The source array of the target quatnerion.

    • srcOffset1: number

      An offset into the array src1.

    • t: number

      Normalized interpolation factor (between 0 and 1).

    Returns void