Expand description
Core math types and operations for the OxiPhysics engine.
All other OxiPhysics crates should import math types from
oxiphysics_core::math rather than depending on nalgebra directly.
Structs§
- Aabb
- Axis-aligned bounding box in 3-D.
- Dual
- A dual number
a + b * εwhereε² = 0. - Frustum
- A view frustum defined by 6 planes (near, far, left, right, top, bottom).
- Plane
- A plane defined by a normal and signed distance from origin.
- Ray
- A ray defined by an origin and direction.
- Unit
- A wrapper that ensures the underlying algebraic entity has a unit norm.
Functions§
- barycentric_
coords - Barycentric coordinates of point
pwith respect to triangle(a, b, c). - bezier_
arc_ length - Arc length of a cubic Bézier curve approximated with
nsegments. - bezier_
cubic - Cubic Bézier curve.
- bspline_
basis3 - B-spline basis functions for a clamped uniform cubic B-spline (degree 3).
- build_
orthonormal_ basis - Build an orthonormal basis
(tangent, bitangent, normal)given a surface normaln(must be unit length). - cartesian_
to_ cylindrical - Convert Cartesian coordinates to cylindrical
(rho, phi, z). - cartesian_
to_ spherical - Convert Cartesian coordinates
(x, y, z)to spherical(r, theta, phi). - catmull_
rom - Catmull-Rom spline interpolation.
- closest_
point_ on_ line - Closest point on line (
origin+ t *dir) to pointp.dirshould be a unit vector. - closest_
point_ on_ segment - Closest point on segment
a–bto pointp. - cross_
matrix - Build the skew-symmetric (cross-product) matrix for
v. - cross_
product_ matrix - Cross product matrix
[a]×such that[a]× * b = a × b. - cylindrical_
to_ cartesian - Convert cylindrical coordinates
(rho, phi, z)to Cartesian. - cylindrical_
to_ vec3 - Convert cylindrical
(rho, phi, z)to a CartesianVec3. - double_
cross_ matrix - Double cross product
a × (a × b)expressed as a matrix timesb: the matrix is-[a]ײ = a*aᵀ - (a·a)*I. - dual_
differentiate - Compute the derivative of
fatxusing dual numbers. - gram_
schmidt - Gram-Schmidt orthogonalization of three linearly-independent vectors.
- gram_
schmidt_ vectors - Gram-Schmidt orthonormalization of up to
nvectors stored invecs. - hermite_
interpolate - Hermite spline interpolation between two points
p0andp1with tangentsm0andm1. Parametertruns from 0 (at p0) to 1 (at p1). - look_at
- Create a look-at view matrix (right-handed).
- mat3_
adjugate - Adjugate (classical adjoint) of a 3×3 matrix:
adj(M) = det(M) * M^{-1}. - mat3_
adjugate_ na - Adjugate of a nalgebra
Mat3(transpose of the cofactor matrix). - mat3_
arr_ inverse - Inverse of a 3×3 matrix. Returns
Noneif singular (|det| < 1e-14). - mat3_
cayley_ hamilton - Verify the Cayley-Hamilton theorem for a 3×3 matrix M.
- mat3_
cofactor - Cofactor matrix of a 3×3 matrix.
- mat3_
compose_ rotations - Compose two rotation matrices:
r_total = r2 * r1(first apply r1, then r2). - mat3_
det - Determinant of a 3×3 matrix.
- mat3_
determinant - Compute the determinant of a 3x3 matrix.
- mat3_
eigenvalues_ symmetric - Compute real eigenvalues of a symmetric 3x3 matrix.
- mat3_
exp_ skew - Matrix exponential of a skew-symmetric matrix (rotation matrix).
- mat3_
frobenius_ norm - Compute the Frobenius norm of a 3x3 matrix.
- mat3_
from_ axis_ angle - Build a rotation matrix from an
axis(unit vector) andangle(radians). - mat3_
from_ cols - Build a 3×3 matrix from three column vectors.
- mat3_
from_ euler_ zyx - Build a rotation matrix from ZYX Euler angles (roll, pitch, yaw) in radians.
- mat3_
gram_ schmidt - Modified Gram-Schmidt applied to the columns of a
Mat3. - mat3_
inverse - Compute the inverse of a 3x3 matrix.
- mat3_
log_ rotation - Matrix logarithm of a rotation matrix
R. - mat3_
mul_ mat3 - Multiply two 3×3 matrices:
a * b. - mat3_
mul_ vec3 - Multiply a 3×3 matrix by a 3-vector:
m * v. - mat3_
outer_ product - Outer product of two 3-vectors:
a ⊗ b(a 3×3 matrix). - mat3_
rotation_ angle - Extract the rotation angle from a 3×3 rotation matrix.
- mat3_
rotation_ axis - Extract the rotation axis (unit vector) from a 3×3 rotation matrix.
- mat3_
rotation_ from_ to - Build a rotation matrix that takes unit vector
fromto unit vectorto. - mat3_
slerp - Interpolate between two rotation matrices using matrix slerp.
- mat3_
to_ euler_ zyx - Extract ZYX Euler angles (yaw, pitch, roll) from a rotation matrix.
- mat3_
trace - Compute the trace of a 3x3 matrix.
- mat3_
transpose - Transpose a 3×3 matrix stored as
[[f64;3\];3](row-major). - mat3_
weighted_ mean - Compute the average of multiple rotation matrices using the iterative
geodesic mean (Moakher 2002).
weightsmust be non-negative and sum to 1. - orthographic
- Create an orthographic projection matrix (right-handed).
- perspective
- Create a perspective projection matrix (right-handed, depth [0, 1]).
- plane_
from_ point_ normal - Create a plane
[nx, ny, nz, d]from a pointpand unit normaln. - plane_
plane_ intersection - Compute the intersection line of two planes.
- plane_
signed_ dist - Signed distance from
pointto the plane[nx, ny, nz, d]. - point_
in_ triangle - Test whether point
plies inside triangle(a, b, c). - point_
to_ line_ distance - Distance from point
pto the line defined byoriginand unitdir. - point_
to_ segment_ distance - Distance from point
pto segmenta–b. - polar_
decomposition - Compute the polar decomposition of a 3×3 matrix
M = R * SwhereRis orthogonal (rotation) andSis symmetric positive semi-definite. - quat_
arr_ conjugate - Convert a unit quaternion
[x,y,z,w]to its conjugate. - quat_
arr_ dot - Dot product of two quaternions (as 4-vectors).
- quat_
arr_ exp - Quaternion exponential for a pure quaternion
v = [x, y, z, 0]. - quat_
arr_ from_ axis_ angle - Create a unit quaternion
[x, y, z, w]from an axis-angle pair. - quat_
arr_ log - Quaternion logarithm for a unit quaternion
q = [x, y, z, w]. - quat_
arr_ normalize - Normalize a quaternion
[x,y,z,w]to unit length. - quat_
arr_ pow - Power of a unit quaternion:
q^t = exp(t * log(q)). - quat_
arr_ rotate_ vec3 - Rotate a 3-vector by a unit quaternion
q = [x,y,z,w]using the sandwich productq * v * q^*. - quat_
arr_ slerp - Spherical linear interpolation between two unit quaternions (format:
[x,y,z,w]). - quat_
arr_ squad_ control - Double-geodesic (SQUAD) interpolation at midpoint between two key frames.
- quat_
blend - Linear blending of two quaternions followed by renormalization (NLerp).
- quat_
double_ cover_ fix - Ensure double-cover consistency: negate
qif its w < 0 so that the canonical representative always has w ≥ 0. - quat_
exp - Quaternion exponential of a pure quaternion
v(w component ignored). - quat_
from_ axis_ angle - Create a quaternion from an axis-angle representation.
- quat_
from_ euler - Create a quaternion from Euler angles (roll, pitch, yaw) in radians.
- quat_
from_ two_ vectors - Build a unit quaternion that rotates
fromontoto. - quat_
geodesic_ distance - Geodesic (angular) distance between two unit quaternions.
- quat_
integrate_ rk4 - Runge–Kutta 4th-order integration of a quaternion ODE.
- quat_
log - Quaternion logarithm of a
UnitQuaternion. - quat_
multiply - Multiply two quaternions
p * q(Hamilton product). Format:[x, y, z, w]. - quat_
nlerp - Normalized linear interpolation (nlerp) between two unit quaternions.
- quat_
slerp - Spherical linear interpolation between two quaternions.
- quat_
squad - SQUAD (Spherical Quadrangle interpolation) for smooth quaternion paths.
- quat_
squad_ control - Build the inner control quaternion
s_ineeded for SQUAD interpolation. - quat_
squad_ na - Spherical cubic interpolation (SQUAD) between two
UnitQuaternions. - quat_
to_ axis_ angle - Convert a unit quaternion
[x, y, z, w]to(axis, angle). - quat_
to_ euler - Convert a quaternion to Euler angles (roll, pitch, yaw) in radians.
- quat_
to_ mat3 - Convert a unit quaternion
[x, y, z, w]to a 3×3 rotation matrix (row-major). - reflect_
direction - Compute the reflection of direction
dabout unit normaln. - rodrigues_
rotate - Rodrigues rotation: rotate vector
varound unitaxisbyangleradians. - sample_
hemisphere_ cosine - Cosine-weighted sample on the unit hemisphere (z ≥ 0).
- sample_
hemisphere_ uniform - Uniformly sample a direction on the unit hemisphere (z ≥ 0) given two
uniform random numbers
u1, u2 ∈ [0, 1). - sample_
unit_ disk_ concentric - Uniformly sample a point on the surface of a unit disk.
- sh_
project_ l1 - Project a radiance function sampled at
nuniformly-spread directions onto the 4 L0+L1 SH coefficients [c00, c1m1, c10, c11]. - sh_y00
- Evaluate real spherical harmonic Y_0^0 (degree 0, order 0).
- sh_y1m1
- Evaluate real spherical harmonic Y_1^{-1} (degree 1, order -1).
- sh_y10
- Evaluate real spherical harmonic Y_1^0 (degree 1, order 0).
- sh_y11
- Evaluate real spherical harmonic Y_1^1 (degree 1, order 1).
- skew_
symmetric - Build a skew-symmetric matrix from a vector (for cross product as matrix multiply).
- spherical_
to_ cartesian - Convert spherical coordinates
(r, theta, phi)to Cartesian(x, y, z). - spherical_
to_ vec3 - Convert spherical
(r, theta, phi)to a CartesianVec3. - spin_
matrix - Spin matrix for angular velocity
omega: the time-derivative of a rotation matrix R satisfiesṘ = omega_hat * Rwhereomega_hat = skew(omega). - symmetric_
eigen3 - Compute eigenvalues and eigenvectors of a real symmetric 3×3 matrix using the Jacobi iteration method.
- three_
plane_ intersection - Compute the intersection point of three planes.
- vec4
- Create a Vec4 from components.
- vec3_
abs - Absolute value of each component of
v. - vec3_
angle_ between - Angle in radians between two non-zero vectors
aandb. - vec3_
clamp - Component-wise clamp of
vto[lo, hi]. - vec3_
cross - Cross product of two 3-vectors:
a × b. - vec3_
decompose - Decompose a
Vec3into components parallel and perpendicular toaxis(which must be a unit vector). - vec3_
lerp - Linear interpolation between two 3-vectors:
a + t*(b-a). - vec3_
max - Component-wise maximum of two
Vec3values. - vec3_
min - Component-wise minimum of two
Vec3values. - vec3_
outer_ product - Outer product of two Vec3 vectors:
a ⊗ bas a nalgebraMat3. - vec3_
project - Project vector
aontoonto. Returns the zero vector ifontois zero. - vec3_
project_ onto - Project
vonto the unit directiononto_unit. - vec3_
project_ onto_ plane - Project a
Vec3onto a plane defined by its unit normaln. - vec3_
project_ onto_ unit - Project vector
vonto unit directiononto_unit. - vec3_
reflect - Reflect vector
vabout unit normaln:v - 2*(v·n)*n. - vec3_
reflect_ about - Reflect
vabout the unit normaln:v - 2*(v·n)*n. - vec3_
reflect_ about_ normal - Reflect vector
vabout unit normaln:v - 2*(v·n)*n. - vec3_
refract - Refract
vabout the unit normalnwith relative index of refractioneta. - vec3_
refract_ ratio - Refract vector
v(unit incident) through a surface with unit normaln. - vec3_
reject - Reject (orthogonal complement) of
vwith respect to unit directionu:reject(v, u) = v - project(v, u). - vec3_
reject_ from - Reject
vfrom the unit directiononto_unit(perpendicular component). - vec3_
rotate_ by_ angle - Rotate vector
varound unitaxisbyangleradians (Rodrigues’ formula). - vec3_
rotate_ by_ quat - Rotate
vby quaternionq. - vec3_
scalar_ triple - Scalar triple product
a · (b × c). - vec3_
signed_ angle - Signed angle (in radians) from
atobmeasured aboutaxis. - vec3_
to_ cylindrical - Convert a Cartesian 3-vector to cylindrical coordinates
(rho, phi, z). - vec3_
to_ spherical - Convert a Cartesian
Vec3to spherical coordinates(r, theta, phi). - vec3_
triple_ product - Scalar triple product:
a · (b × c). - vec3_
vector_ triple - Vector triple product
a × (b × c) = b*(a·c) - c*(a·b). - vec4_
direction - Homogeneous direction (w=0).
- vec4_
point - Homogeneous point (w=1).
- vec4_
to_ vec3 - Project a Vec4 back to Vec3 by dividing by w.
Type Aliases§
- Mat3
- 3x3 matrix type alias.
- Mat4
- 4x4 matrix type alias.
- Matrix3
- A stack-allocated, column-major, 3x3 square matrix.
- Matrix4
- A stack-allocated, column-major, 4x4 square matrix.
- Point3
- A statically sized 3-dimensional column point.
- Quat
- Quaternion type alias.
- Real
- Scalar type used throughout the engine (f64 by default).
- Unit
Quaternion - A unit quaternions. May be used to represent a rotation.
- Vec3
- 3D vector type alias.
- Vec4
- 4D vector type alias.
- Vector3
- A stack-allocated, 3-dimensional column vector.
- Vector4
- A stack-allocated, 4-dimensional column vector.