Class Quaternion

The Quaternion is used to represent orientations and rotations. The class follows the 'copy-on-write' pattern, which means that every operation returns a copy of the quaternion with updated values. It also implies that the values of the quaternion cannot be directly modified.

The concept of immutability improves sharing of objects as all types in TypeScript are assigned by identity, instead of by-value (e.g. a copy) as in other programming languages like C.

Constructors

  • Parameters

    • Optionalx: number
    • Optionaly: number
    • Optionalz: number
    • Optionalw: number

    Returns Quaternion

Properties

_w: number
_x: number
_y: number
_z: number
identity: Quaternion

Quaternion representing no rotation.

Quaternion with all zero elements.

Accessors

  • get forward(): Vector3
  • Gets the positive z-axis of the coordinate system transformed by this quaternion.

    Returns Vector3

  • get right(): Vector3
  • Gets the positive x-axis of the coordinate system transformed by this quaternion.

    Returns Vector3

  • get up(): Vector3
  • Gets the positive y-axis of the coordinate system transformed by this quaternion.

    Returns Vector3

  • get w(): number
  • Returns number

  • set w(value): void
  • Parameters

    • value: number

    Returns void

  • get x(): number
  • Returns number

  • set x(value): void
  • Parameters

    • value: number

    Returns void

  • get y(): number
  • Returns number

  • set y(value): void
  • Parameters

    • value: number

    Returns void

  • get z(): number
  • Returns number

  • set z(value): void
  • Parameters

    • value: number

    Returns void

Methods

  • Copies all properties defined by the prototype of Quaternion from other to this instance.

    Parameters

    Returns Quaternion

  • Clones this instance and returns a new Quaternion with identical values.

    Returns Quaternion

  • Returns a copy of the current Quaternion divided by the factor.

    Parameters

    • factor: number

    Returns Quaternion

  • Divides this Quaternion by the given factor and returns it.

    Parameters

    • factor: number

    Returns Quaternion

  • Calculates the inverse of the quaternion. Inverse quaternion has the opposite rotation of the original.

    Returns Quaternion

  • Multiply this Quaternion by the given factor and returns it.

    Parameters

    • factor: number

    Returns Quaternion

  • Normalizes the quaternion.

    Returns number

    Length of the quaternion prior to normalization.

  • Calculates a dot product between two quaternions.

    Parameters

    Returns number

    Dot product between the two quaternions.

  • Evaluates the expression and assigns it to the quaternion.

    Parameters

    • fnExpression: (() => number)

      The expression to evaluate.

        • (): number
        • Returns number

    Returns Quaternion

    A reference to this vector

    Make sure to read up on how Vector expressions work in Typescript.

    MathEx.eval for detailed documentation, limitations and considerations.

  • Accesses a specific component of the quaternion.

    Parameters

    • index: number

      Index of the component (0 - x, 1 - y, 2 - z, 3 - w).

    Returns number

    Value of the specific component.

  • Returns a copy of the inverse of the quaternion. Quaternion must be non-zero. Inverse quaternion has the opposite rotation of the original.

    Returns Quaternion

  • Returns whether the provided quaternion, given a error margin, contains the same values as this one.

    Parameters

    • rhs: Immutable<Quaternion>

      The other quaternion to compare

    • Optionalepsilon: number

      Optional. Error margin within which the numbers should be considered equal.

    Returns boolean

    True if equal, false otherwise.

  • Returns whether this quaternion is equal to given one.

    Parameters

    Returns boolean

  • Returns a copy of the current Quaternion multiplied by the factor.

    Parameters

    • factor: number

    Returns Quaternion

  • Applies quaternion rotation to the specified point.

    Parameters

    Returns Vector3

    Point rotated by the quaternion.

  • Initializes the quaternion with rotation that rotates from one direction to another.

    Parameters

    Returns void

  • Assigns the value to the element at the specified index.

    Parameters

    • index: number
    • value: number

    Returns void

  • Initializes the quaternion with rotation that rotates from one direction to another.

    Parameters

    • fromDirection: Immutable<Vector3>

      rotation to start at.

    • toDirection: Immutable<Vector3>

      rotation to end at.

    • fallbackAxis: Immutable<Vector3>

      Fallback axis to use if the from/to vectors are almost completely opposite. Fallback axis should be perpendicular to both vectors.

    Returns void

  • Initializes the quaternion so that it orients an object so it faces in te provided direction.

    Parameters

    Returns void

  • Initializes the quaternion so that it orients an object so it faces in te provided direction.

    Parameters

    Returns void

  • Converts this instance to an array with 4 elements.

    Returns [number, number, number, number]

  • Converts a quaternion into an orthonormal set of axes.

    Parameters

    • xAxis: Vector3

      Output normalized x axis.

    • yAxis: Vector3

      Output normalized y axis.

    • zAxis: Vector3

      Output normalized z axis.

    Returns void

  • Converts the quaternion rotation into axis/angle rotation.

    Returns {
        angle: rsx.Degree;
        axis: Vector3;
    }

  • Converts the quaternion rotation into euler angle (pitch/yaw/roll) rotation.

    Returns Vector3

    rotation as euler angles, in degrees.

  • Converts a quaternion rotation into a rotation matrix.

    Returns Matrix3

    Matrix representing the rotation.

  • Returns a string representation of an object.

    Returns string

  • Calculates a dot product between two quaternions.

    Parameters

    Returns number

    Dot product between the two quaternions.

  • Initializes the quaternion from orthonormal set of axes.

    Parameters

    Returns Quaternion

    Quaternion that represents a rotation from base axes to the specified set of axes.

  • Creates a quaternion from axis/angle rotation.

    Parameters

    Returns Quaternion

    Quaternion that rotates an object around the specified axis for the specified amount.

  • Creates a quaternion from the provided euler angle (pitch/yaw/roll) rotation.

    Parameters

    • xAngle: rsx.Degree

      Pitch angle of rotation.

    • yAngle: rsx.Degree

      Yar angle of rotation.

    • zAngle: rsx.Degree

      Roll angle of rotation.

    • Optionalorder: EnumValue<EulerAngleOrder, number>

      The order in which rotations will be applied. Different rotations can be created depending on the order.

    Returns Quaternion

    Quaternion that can rotate an object to the specified angles.

  • Creates a quaternion from the provided euler angle (pitch/yaw/roll) rotation.

    Parameters

    • euler: Immutable<Vector3>

      Euler angles in degrees.

    • Optionalorder: EnumValue<EulerAngleOrder, number>

      The order in which rotations will be applied. Different rotations can be created depending on the order.

    Returns Quaternion

    Quaternion that can rotate an object to the specified angles.

  • Creates a quaternion from a rotation matrix.

    Parameters

    Returns Quaternion

    Newly created quaternion that has equivalent rotation as the provided rotation matrix.

  • Creates a quaternion with rotation that rotates from one direction to another.

    Parameters

    • fromDirection: Immutable<Vector3>

      rotation to start at.

    • toDirection: Immutable<Vector3>

      rotation to end at.

    • fallbackAxis: Immutable<Vector3>

      Fallback axis to use if the from/to vectors are almost completely opposite. Fallback axis should be perpendicular to both vectors.

    Returns Quaternion

    Quaternion that rotates an object from fromDirection to toDirection

  • Returns the inverse of the quaternion. Inverse quaternion has the opposite rotation of the original.

    Parameters

    Returns Quaternion

    Inverse of the provided quaternion.

    Quaternion must be non-zero

  • Determines whether both Quaternions are equal within an error margin.

    Parameters

    • lhs: Immutable<Quaternion>

      First quaternion to compare.

    • rhs: Immutable<Quaternion>

      Second quaternion to compare.

    • Optionalepsilon: number

      Optional. Error margin within which the numbers should be considered equal.

    Returns boolean

    True if equal, false otherwise.

  • Creates a quaternion that orients an object so it faces in the provided direction.

    Parameters

    Returns Quaternion

  • Performs a spherical interpolation between two quaternions.

    Parameters

    • from: Immutable<Quaternion>

      Start quaternion.

    • to: Immutable<Quaternion>

      End quaternion.

    • t: number

      Interpolation factor in range [0...1] that determines how much to interpolate between from and to.

    • OptionalshortestPath: boolean

      true to take the shortest or longest path. Default: true.

    Returns Quaternion

    Interpolated quaternion representing a rotation between from and to.

  • Performs a spherical interpolation between two quaternions using a maximumAngle constraint.

    Parameters

    Returns Quaternion

    Interpolated quaternion representing a rotation between from and to.

  • Creates a quaternion with rotation that rotates from one direction to another.

    Parameters

    Returns Quaternion

    Quaternion that rotates an object from fromDirection to toDirection

  • Creates a quaternion that orients an object so it faces in the provided direction.

    Parameters

    Returns Quaternion