Skip to content
FutureBlitz

    Install

    Import std.math.quat

    std.math.quat

    Quat: a rotation, as a unit quaternion of Floats, x, y, z, and w. Angles are radians, and the rotations turn counterclockwise about an axis that points at the viewer, by the right-hand rule. Euler angles go in Y, X, Z order, as a camera's yaw, pitch, and roll: Z first, then X, then Y.

    std/math/quat.fb

    Types

    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.

    std/math/quat.fb, line 13

    • 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 text, as a string interpolation like "{value}" shows it.

      Doc from std.core.interfaces.Printable.ToString.

    • 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.

    Functions

    Dot function

    Public Function Dot(a: Quat, b: Quat): Float

    The sum of the products of the components: the cosine of half the angle between two rotations.

    std/math/quat.fb, line 182

    Length function

    Public Function Length(q: Quat): Float

    The quaternion's length, which a rotation's is 1, worked out in Doubles, as a Vec4's is.

    std/math/quat.fb, line 185

    Normalize function

    Public Function Normalize(q: Quat): Quat

    The quaternion scaled to length 1, as rounding over many rotations wears it, worked out in Doubles, as a Vec4's is. A zero one gives no rotation.

    std/math/quat.fb, line 189

    Inverse function

    Public Function Inverse(q: Quat): Quat

    The opposite rotation, which undoes it: for a unit quaternion, as a rotation is, its conjugate.

    std/math/quat.fb, line 196

    Lerp function

    Public Function Lerp(a: Quat, b: Quat, t: Float): Quat

    The rotation t of the way from a to b, the short way around, as a straight line between them scaled to length 1: quicker than Slerp, and nearly as smooth for angles that aren't large.

    std/math/quat.fb, line 200

    Slerp function

    Public Function Slerp(a: Quat, b: Quat, t: Float): Quat

    The rotation t of the way from a to b, the short way around, at an even speed.

    std/math/quat.fb, line 207

    Angle function

    Public Function Angle(a: Quat, b: Quat): Float

    The angle in radians, from 0 to Pi, of the rotation from a to b, from its half angle's sine and cosine, which keep small angles exact.

    std/math/quat.fb, line 226

    IsClose function

    Public Function IsClose(a: Quat, b: Quat): Bool

    Whether the two are close as rotations, as IsClose tells for each component, with q and -q the same rotation.

    std/math/quat.fb, line 233

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