Skip to documentation
SLOP

tiny.linear.Quat

Reference tiny.linear Quat

Defined in tiny.linear.

API (22)

Actions

Public operations.

Types and contracts

Public types and contracts.

Fields and members

Public fields and members.

No direct callersNo direct callstiny.linearQuat
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/linear/src/quaternion.zig:11

zig
pub const Quat = extern struct {    w: f32 = 1,    x: f32 = 0,    y: f32 = 0,    z: f32 = 0,    pub const identity: Quat = .{};    /// Above this cosine between endpoints, `slerp` interpolates linearly and    /// renormalizes, because the arc is too short for a stable sine ratio.    pub const slerp_linear_cosine: f32 = 0.9995;    pub fn init(w: f32, x: f32, y: f32, z: f32) Quat {        return .{ .w = w, .x = x, .y = y, .z = z };    }    /// Lanes in storage order: w, x, y, z.    pub fn fromArray(lanes: [4]f32) Quat {        return .{ .w = lanes[0], .x = lanes[1], .y = lanes[2], .z = lanes[3] };    }    /// Lanes in storage order: w, x, y, z.    pub fn toArray(q: Quat) [4]f32 {        return .{ q.w, q.x, q.y, q.z };    }    /// The rotation by `angle` radians about the unit vector `axis`.    pub fn fromAxisAngle(axis: Vec3, angle: f32) Quat {        const half = angle * 0.5;        const sin_half = @sin(half);        return .{            .w = @cos(half),            .x = axis.x * sin_half,            .y = axis.y * sin_half,            .z = axis.z * sin_half,        };    }    /// The imaginary part `(x, y, z)`.    pub fn vector(q: Quat) Vec3 {        return .{ .x = q.x, .y = q.y, .z = q.z };    }    pub fn add(a: Quat, b: Quat) Quat {        return .{ .w = a.w + b.w, .x = a.x + b.x, .y = a.y + b.y, .z = a.z + b.z };    }    pub fn sub(a: Quat, b: Quat) Quat {        return .{ .w = a.w - b.w, .x = a.x - b.x, .y = a.y - b.y, .z = a.z - b.z };    }    pub fn scale(q: Quat, s: f32) Quat {        return .{ .w = q.w * s, .x = q.x * s, .y = q.y * s, .z = q.z * s };    }    /// The same rotation with every lane negated.    pub fn negate(q: Quat) Quat {        return .{ .w = -q.w, .x = -q.x, .y = -q.y, .z = -q.z };    }    /// The inverse rotation of a unit quaternion.    pub fn conjugate(q: Quat) Quat {        return .{ .w = q.w, .x = -q.x, .y = -q.y, .z = -q.z };    }    /// The four-lane dot product, summed from w.    pub fn dot(a: Quat, b: Quat) f32 {        return a.w * b.w + a.x * b.x + a.y * b.y + a.z * b.z;    }    pub fn length(q: Quat) f32 {        return @sqrt(q.dot(q));    }    /// The unit quaternion along `q`, or null when its length is at most    /// `min_length` or is NaN.    pub fn normalized(q: Quat, min_length: f32) ?Quat {        assert(min_length >= 0);        const len = q.length();        if (!(len > min_length)) return null;        return q.scale(1 / len);    }    /// The Hamilton product: rotating by `b`, then by `a`.    pub fn mul(a: Quat, b: Quat) Quat {        return .{            .w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z,            .x = a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y,            .y = a.w * b.y - a.x * b.z + a.y * b.w + a.z * b.x,            .z = a.w * b.z + a.x * b.y - a.y * b.x + a.z * b.w,        };    }    /// `v` rotated by the unit quaternion `q`, as    /// `v + (2w (u × v) + 2 u × (u × v))` with `u` the imaginary part.    pub fn rotate(q: Quat, v: Vec3) Vec3 {        const u = q.vector();        const uv = u.cross(v);        const uuv = u.cross(uv);        return v.add(uv.scale(2 * q.w).add(uuv.scale(2)));    }    /// Spherical interpolation between unit quaternions along the shorter    /// arc: `a` at `t = 0`, and `b` or `-b` at `t = 1`.    pub fn slerp(a: Quat, b: Quat, t: f32) Quat {        var end = b;        var cosine = a.dot(b);        if (cosine < 0) {            end = b.negate();            cosine = -cosine;        }        if (cosine > slerp_linear_cosine) {            return a.add(end.sub(a).scale(t)).normalized(0).?;        }        const theta = std.math.acos(@min(cosine, 1));        const sin_theta = @sin(theta);        const weight_a = @sin((1 - t) * theta) / sin_theta;        const weight_b = @sin(t * theta) / sin_theta;        return a.scale(weight_a).add(end.scale(weight_b));    }};

Source: lib/linear/src/root.zig:11

zig
pub const Quat = quaternion.Quat;
Called byCallsNo direct callsprivate; no linkfun.sdfii.src.engine.abi.physicssdfii quat integrateprivate; no linkfun.sdfii.src.engine.abi.physicssdfii quat multiplyprivate; no linkfun.sdfii.src.engine.abi.physicssdfii quat slerpprivate; no linkfun.sdfii.src.engine.abi.physicssdfii quat to matrixprivate; no linkfun.sdfii.src.properties.physicsquaternion matrix is rotation+2 moreQuatfromArray
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstiny.rigtiny.linearquatFromAxisAngletest sourcelib.linear.src.affinetest: product composes right to lefttest sourcelib.linear.src.affinetest: scale applies before rotation a...test sourcelib.linear.src.matrixtest: matrix product composes right t...test sourcelib.linear.src.matrixtest: quaternion matrix agrees with q...+7 moreQuatfromAxisAngle
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest; no linkfun.sdfii.src.engine.system.physics.bodytest: 90 degrees about Y axistest; no linkfun.sdfii.src.engine.system.physics.bodytest: PhysicsBody defaults match Pyth...test; no linkfun.sdfii.src.engine.system.physics.bodytest: axis-angle zero angle returns i...test; no linkfun.sdfii.src.engine.system.physics.bodytest: identity quaternion to axis-ang...test; no linkfun.sdfii.src.engine.system.physics.bodytest: normalize general quaternion+12 moreQuatinit
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsprivate sourcelib.linear.src.testarithmeticDigestQuatmul
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsprivate sourcelib.linear.src.testarithmeticDigestQuatrotate
Static calls · unresolved targets: 1 · external targets: 4.
Called byCallsNo direct callsprivate sourcelib.linear.src.testarithmeticDigestQuatslerp
Static calls · unresolved targets: 1 · external targets: 5.

Complete caller list for Quat.fromArray

7 direct callers.

Complete caller list for Quat.fromAxisAngle

12 direct callers.

Complete caller list for Quat.init

17 direct callers.

Audit

Definitions19
Public names19
Members4
Version26.7.0
Revisiondaab053ee433