Skip to main content

Module math

Module math 

Source
Expand description

The scalar, vector and rotation primitives the rest of the vocabulary is built from: the f32 transcendentals core leaves to a math library, the 3-component vector ops every layout and transform reaches for, and the quaternion / Euler convention rotations are authored and stepped in.

Modules§

vec3
The crate’s shared 3-component vector math. Every module that needs a dot, cross, or component-wise op reaches for these rather than redeclaring them.

Functions§

acos
Arc cosine, in radians.
asin
Arc sine, in radians.
atan2
Arc tangent of y / x, in radians, using both signs to pick the quadrant.
ceil
Smallest integer at or above x.
cos
Cosine of an angle in radians.
euler_yxz_deg_from_quat
Engine Euler degrees [pitch, yaw, roll] for a rotation quaternion, which need not be normalised.
exp
e raised to x.
exp2
2 raised to x.
floor
Largest integer at or below x.
fract
Fractional part, keeping the sign of x.
hypot
Length of the hypotenuse of a right triangle with legs x and y, without the intermediate overflow of sqrt(x * x + y * y).
ln
Natural logarithm.
log2
Base-2 logarithm.
mul_add
x * y + z with a single rounding.
powf
x raised to n.
powi
x raised to the integer power n, by squaring. Matches the expansion f32::powi lowers to rather than routing through powf, which would round differently.
quat_from_axis_angle
The rotation quaternion for angle_rad about axis, which need not be normalised. An axis too short to have a direction yields the identity.
quat_from_euler_yxz_deg
The rotation quaternion for engine Euler degrees [pitch, yaw, roll], applied yaw then pitch then roll.
quat_normalize
A rotation quaternion scaled to unit length, or the identity when q is too short to have a direction.
rem_euclid
Least nonnegative remainder of x (mod rhs).
round
Nearest integer, with halves rounded away from zero.
sin
Sine of an angle in radians.
sin_cos
Sine and cosine of an angle in radians.
sqrt
Square root.
tan
Tangent of an angle in radians.
trunc
Integer part, discarding the fraction and keeping the sign of x.

Type Aliases§

Quat
Unit quaternion (x, y, z, w) representing a rotation.