Taos API Reference
    Preparing search index...

    Class Quaternion

    Unit quaternion representing a 3D rotation, stored as (x, y, z, w) with w as the scalar part.

    Index

    Constructors

    Properties

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

    Methods

    • Builds a quaternion from intrinsic Euler angles (radians) applied in XYZ order.

      Parameters

      • x: number

        rotation around the X axis (pitch)

      • y: number

        rotation around the Y axis (yaw)

      • z: number

        rotation around the Z axis (roll)

      Returns Quaternion

    • Extracts the rotation of a matrix as a unit quaternion. Only the upper-left 3×3 (the rotation/basis part) is read, so a TRS or look-at matrix works directly provided its basis is orthonormal (no non-uniform scale). Uses the numerically-stable branch-by-largest-diagonal method.

      Handy for deriving an orientation from a constructed basis — e.g. a chase camera does Quaternion.fromRotationMatrix(Mat4.lookAt(eye, target, up).invert()).

      Parameters

      • m: Mat4

        Column-major matrix whose 3×3 rotation part is orthonormal.

      Returns Quaternion

    • Builds the rotation that aims an object's local forward axis (Vec3.FORWARD, i.e. -Z) along forward in world space. The inverse of Vec3.FORWARD-relative worldDirection() readers like DirectionalLight / SpotLight: set go.rotation = Quaternion.fromForward(dir) and the light then shines down dir.

      up only resolves the roll about forward (irrelevant for a directional or spot light); it defaults to world up, swapping to world right when forward is nearly vertical so the basis stays well-conditioned.

      Parameters

      • forward: Vec3

        Desired world-space forward direction (normalized internally).

      • Optionalup: Vec3

        Optional reference up; defaults to Vec3.UP (or Vec3.RIGHT near-vertical).

      Returns Quaternion

    • Sets this quaternion to represent a rotation of rad radians around axis (axis is normalized internally).

      Parameters

      • axis: Vec3

        The axis of rotation.

      • rad: number

        The angle of rotation in radians.

      Returns void

    • Sets this quaternion from intrinsic Euler angles (radians) applied in XYZ order.

      Parameters

      • x: number

        rotation around the X axis (pitch)

      • y: number

        rotation around the Y axis (yaw)

      • z: number

        rotation around the Z axis (roll)

      Returns void

    • Decomposes this quaternion into intrinsic Euler angles (radians) in XYZ order, matching the convention used by fromEuler and setEuler.

      At the gimbal-lock poles (|pitch| ≈ π/2), roll is fixed at 0 and yaw absorbs the combined rotation.

      Returns Vec3

    • Sets this quaternion to the identity rotation (0, 0, 0, 1). Useful for reusing an existing quaternion instance instead of creating a new one.

      Returns void

    • Spherical linear interpolation from this to b at parameter t in [0, 1].

      Picks the shorter arc (negates b if the dot product is negative) and falls back to normalized linear interpolation when the angle between the quaternions is tiny.

      Parameters

      Returns Quaternion