Skip to content
FutureBlitz

    Install

    Import std.math.quat

    Quat

    std.math.quat

    struct

    Public Struct Quat Implements Equatable, Printable

    A rotation: x, y, and z are its axis times the sine of half its angle, and w the cosine of half of it. q * v turns v, and a * b turns by b, then by a. q and -q are the same rotation.

    Examples

    
    Local turn = Quat.FromAxisAngle(Vec3(0, 1, 0), Deg(90))
    Expect(IsClose(turn * Vec3(1, 0, 0), Vec3(0, 0, -1)))
    Local half = Slerp(Quat.Identity, turn, 0.5)
    Expect(IsClose(Angle(Quat.Identity, half), Deg(45)))
    Expect(IsClose(Inverse(turn) * (turn * Vec3(1, 2, 3)), Vec3(1, 2, 3)))

    std/math/quat.fb, line 40

    • Public Field x: Float field #

      Its axis's x times the sine of half its angle.

    • Public Field y: Float field #

      Its axis's y times the sine of half its angle.

    • Public Field z: Float field #

      Its axis's z times the sine of half its angle.

    • Public Field w: Float field #

      The cosine of half its angle.

    • Public Static Property Identity: Quat property #

      No rotation.

    • Public Static Method FromAxisAngle(axis: Vec3, angle: Float): Quat static method #

      The rotation by the angle, in radians, about the axis. A zero axis gives no rotation.

    • Public Static Method FromEuler(x: Float, y: Float, z: Float): Quat static method #

      The rotation by Euler angles in radians: z about Z, then x about X, then y about Y, as a camera's roll, pitch, and yaw.

    • Public Static Method FromMat3(m: Mat3): Quat static method #

      The rotation a rotation matrix makes, whose columns are the turned axes.

    • Public Static Method FromTo(from: Vec3, to: Vec3): Quat static method #

      The shortest rotation that turns the direction from to the direction to, however small. Opposite ones turn half a turn about an axis at right angles to them, and a zero one gives no rotation.

    • @PanicsAtCaller Public Static Method LookRotation(forward: Vec3, up: Vec3): Quat static method #

      The rotation that turns Forward, -Z, to forward, with Up turned as near to up as it goes: how an object or camera at a place faces forward. A zero forward, or an up along it, panics.

    • Public Method ToMat3(): Mat3 method #

      The rotation as a matrix, whose columns are the turned axes.

    • Public Method ToMat4(): Mat4 method #

      The rotation as a Mat4 that moves nothing.

    • Public Method ToAxisAngle(): (Vec3, Float) method #

      The axis, of length 1, and the angle in radians, from 0 to Tau, it turns about it. No rotation gives the X axis and 0.

    • Public Method ToEuler(): Vec3 method #

      The Euler angles in radians, as FromEuler takes them: x from -Pi / 2 to Pi / 2, and y and z from -Pi to Pi. Within about 0.02 degrees of x's quarter turn, where y and z turn about nearly one axis and Floats can't tell them apart, x is the quarter turn and z is 0.

    • Public Method ToEulerDegrees(): Vec3 method #

      The Euler angles in degrees, for editors, as ToEuler gives them in radians.

    • Public Method ToString(): String method #

      Its components, as "(0, 0, 0, 1)".

    • Operator *(a: Quat, b: Quat): Quat operator #

      The rotation by b, then by a.

    • Operator *(q: Quat, v: Vec3): Vec3 operator #

      The vector turned by the rotation.

    • Operator -(q: Quat): Quat operator #

      The same rotation, with every component's sign turned.

    Report an issue with this page or with FutureBlitz on GitHub.