← Standard library

quaternion

struct quaternion

Available without an import.

A 3D rotation represented by four floating-point components (x, y, z, w), with w the scalar part. Useful for composing and interpolating rotations without Euler-angle gimbal lock. Rotation methods accept angle values.

api fn Main() : int32 {
    var rotation = quaternion.FromAxisAngle(float3.UnitZ, 90.degrees);
    var turned = quaternion.RotateVector(rotation, float3.UnitX);
    return turned.y > 0.999f && turned.x > -0.001f && turned.x < 0.001f ? 1 : 0;
}

Quaternion.wax:17

Members

xfield

public float x

The X component of the vector part.

Quaternion.wax:22

yfield

public float y

The Y component of the vector part.

Quaternion.wax:26

zfield

public float z

The Z component of the vector part.

Quaternion.wax:30

wfield

public float w

The scalar component.

Quaternion.wax:34

constructorconstructor

public constructor (float x, float y, float z, float w)

Stores x/y/z/w without normalization. Rotation operations expect unit quaternions unless they explicitly normalize.

Quaternion.wax:40

FromFloat4constructor

public constructor FromFloat4 (float4 v)

Copies x/y/z/w from a vector without normalization.

Quaternion.wax:50

Identitygetter

public static get Identity() : quaternion

The identity rotation (0, 0, 0, 1).

Quaternion.wax:62

lengthSquaredgetter

public get lengthSquared() : float

Returns the sum of squares of all four components.

Quaternion.wax:71

lengthgetter

public get length() : float

Returns the Euclidean magnitude of all four components.

Quaternion.wax:78

normalizedgetter

public get normalized() : quaternion

Returns a unit quaternion, or Identity when the magnitude is zero.

Quaternion.wax:85

conjugategetter

public get conjugate() : quaternion

Negates the vector part, preserving w. Equals the inverse for a unit quaternion.

Quaternion.wax:96

inversegetter

public get inverse() : quaternion

Returns the conjugate divided by squared magnitude, or Identity for a zero quaternion.

Quaternion.wax:103

isIdentitygetter

public get isIdentity() : bool

Tests exactly for (0, 0, 0, 1), without tolerance or sign-equivalent rotation matching.

Quaternion.wax:114

toFloat4getter

public get toFloat4() : float4

Copies x/y/z/w into a four-component vector.

Quaternion.wax:121

Dotmethod

public static fn Dot(quaternion a, quaternion b) : float

Returns the four-component dot product.

Quaternion.wax:128

FromAxisAnglemethod

public static fn FromAxisAngle(float3 axis, angle a) : quaternion

Normalizes the axis and constructs its rotation by the supplied angle. Supply a nonzero axis.

Quaternion.wax:136

FromEulermethod

public static fn FromEuler(float3 eulerRadians) : quaternion

Constructs from X/Y/Z Euler angles in radians, composed as Z * Y * X (X applied first to a column vector).

Quaternion.wax:148

RotateVectormethod

public static fn RotateVector(quaternion q, float3 v) : float3

Rotates v by q. Supply a unit quaternion.

Quaternion.wax:171

Slerpmethod

public static fn Slerp(quaternion a, quaternion b, float t) : quaternion

Interpolates unit rotations along the shorter arc, correcting the sign of b when needed. Uses normalized linear interpolation near parallel inputs. Does not clamp t; returns a normalized result.

Quaternion.wax:180

NLerpmethod

public static fn NLerp(quaternion a, quaternion b, float t) : quaternion

Linearly interpolates components and normalizes. Does not clamp t or choose a sign-equivalent shorter arc; a zero intermediate returns Identity.

Quaternion.wax:212

Anglemethod

public static fn Angle(quaternion a, quaternion b) : angle

Returns the smaller angular separation between normalized rotations in [0, pi]. Treats opposite-sign quaternions as the same rotation and zero quaternions as Identity.

Quaternion.wax:226

ToFloat3x3method

public static fn ToFloat3x3(quaternion q) : float3x3

Normalizes q and returns its column-major 3D rotation matrix. A zero quaternion produces Identity.

Quaternion.wax:238

ToFloat4x4method

public static fn ToFloat4x4(quaternion q) : float4x4

Normalizes q and returns its homogeneous rotation matrix with no translation. A zero quaternion produces Identity.

Quaternion.wax:261

ToStringmethod

public fn ToString() : string

Formats x/y/z/w in parentheses separated by commas.

Quaternion.wax:284

ToStringBuffermethod

public fn ToStringBuffer(StringBuilder builder) : int32

Appends the component representation and returns the number of UTF-8 bytes appended.

Quaternion.wax:293