rs-math3d
rs-math3d is a no_std-friendly 2D/3D math library focused on computer graphics and geometry. It provides vectors, matrices, quaternions, transforms, and common geometric primitives with utility traits for intersection and distance queries.
Features
- Vector math (2D/3D/4D), dot/cross products, swizzles, and float-only normalization helpers
- Matrix math (2x2/3x3/4x4), determinants, and float-only inverses and affine fast-paths
- Quaternions and transforms for floating-point rotations and projections
- Geometric primitives: rays, planes, triangles, boxes, spheres, line segments
- Query traits for intersection and distance computations
no_stdsupport with an optionalstdfeature
Integer vectors, boxes, rectangles, and matrix arithmetic are supported for discrete geometry
and storage. Operations that require fractional results, such as normalization, inversion,
quaternions, transforms, rays, planes, and geometric queries, are restricted to f32/f64.
Usage
Add to Cargo.toml:
[]
= { = "0.12.0", = false }
Select one math backend:
= { = "0.12.0", = false, = ["std"] }
= { = "0.12.0", = false, = ["libm"] }
= { = "0.12.0", = false, = ["system-libm"] }
When no math backend feature is selected, normal library builds fall back to system-libm.
Test builds without an explicit backend use std.
If more than one backend feature is enabled, precedence is std, then libm, then
system-libm.
Behavior Notes
Ray/Tri3intersection is a true ray query: hits behind the ray origin are rejected. Use the correspondingLine/Tri3intersection when you want the infinite-line result.ParametricPlane::projectsolves the 2x2 Gram system of the plane axes, so projection works for non-orthogonal axes as well as orthogonal ones.Sphere3::newcanonicalizes the radius withabs(radius).Quat::mat3andQuat::mat4normalize the quaternion before converting it to a matrix.Plane::from_quadandPlane::try_from_quaduse a diagonal-derived representative plane. They do not validate that the four vertices are coplanar.transforms::lookatassumeseye != destand anupvector that is not parallel to the view direction. Violating those preconditions yields non-finite output.Tri3::barycentric_coordinatesassumes a non-degenerate triangle. Degenerate triangles produce non-finite coordinates.
Example
use Vector3;
use transforms;
use EPS_F32;
use PI;
Modules
- vector: vector types and operations
- matrix: matrix types and operations
- quaternion: quaternion math for rotations
- transforms: common 3D transforms
- primitives: geometric shapes and intersection helpers
- queries: query traits and implementations
- basis: coordinate system basis helpers
- scalar: scalar traits and constants