Expand description
§rs-math3d
A no_std 3D mathematics library for Rust, providing vectors, matrices,
quaternions, and geometric primitives for computer graphics applications.
§Features
- No standard library required: Works in embedded and WASM environments
- Generic types: All types are generic over scalar types (f32, f64, i32, i64)
- Column-major matrices: Compatible with OpenGL and similar APIs
- Comprehensive operations: Full suite of vector, matrix, and quaternion operations
- Geometric primitives: Rays, planes, triangles, spheres, and more
§Quick Start
use rs_math3d::{Vector, Vector3, Matrix4, Quat, EPS_F32};
use rs_math3d::transforms;
// Create vectors
let v1 = Vector3::new(1.0, 2.0, 3.0);
let v2 = Vector3::new(4.0, 5.0, 6.0);
let dot_product = Vector3::dot(&v1, &v2);
// Create transformation matrices
let translation = transforms::translate(Vector3::new(10.0, 0.0, 0.0));
let rotation = transforms::rotation_from_axis_angle(
&Vector3::new(0.0, 1.0, 0.0),
std::f32::consts::PI / 4.0,
EPS_F32,
).unwrap();
// Use quaternions for rotations
let q = Quat::of_axis_angle(
&Vector3::new(0.0, 0.0, 1.0),
std::f32::consts::PI / 2.0,
EPS_F32,
).unwrap();
let rotation_matrix = q.mat4();§Modules
vector: 2D, 3D, and 4D vectors with arithmetic operationsmatrix: 2x2, 3x3, and 4x4 matrices with linear algebra operationsquaternion: Quaternions for 3D rotationstransforms: Common transformation matrices (translate, rotate, scale, project)primitives: Geometric primitives (rays, planes, triangles, boxes, spheres)queries: Intersection and distance queries between primitivesbasis: Coordinate system basis representationscalar: Traits for generic numeric operations
Re-exports§
pub use matrix::Matrix2;pub use matrix::Matrix3;pub use matrix::Matrix4;pub use quaternion::Quat;pub use scalar::FloatScalar;pub use scalar::Scalar;pub use scalar::EPS_F32;pub use scalar::EPS_F64;pub use vector::CrossProduct;pub use vector::FloatVector;pub use vector::Swizzle2;pub use vector::Swizzle3;pub use vector::Vector;pub use vector::Vector2;pub use vector::Vector3;pub use vector::Vector4;pub use basis::*;pub use primitives::*;pub use queries::*;pub use transforms::*;
Modules§
- basis
- Coordinate basis and reference frame utilities.
- matrix
- Matrix mathematics module providing 2x2, 3x3, and 4x4 matrices.
- primitives
- Geometric primitives for 3D graphics and collision detection.
- quaternion
- Quaternion operations and conversions. Quaternion math for rotations and orientation.
- queries
- Intersection and distance query traits and helpers. Intersection and distance query traits and implementations.
- scalar
- Scalar trait definitions for generic numeric operations.
- transforms
- 3D transformation functions for computer graphics.
- vector
- Vector mathematics module providing 2D, 3D, and 4D vector operations.
Functions§
- color4b
- Creates an RGBA color from byte components.
Type Aliases§
- Basisd
- Double-precision basis.
- Basisf
- Single-precision basis.
- Box3d
- 3D double-precision axis-aligned bounding box.
- Box3f
- 3D single-precision axis-aligned bounding box.
- Color4b
- 4-component byte color (RGBA).
- Dimensionf
- Single-precision dimensions.
- Dimensioni
- Integer dimensions.
- Line2d
- 2D double-precision line.
- Line2f
- 2D single-precision line.
- Line3d
- 3D double-precision line.
- Line3f
- 3D single-precision line.
- Mat2d
- 2x2 double-precision matrix.
- Mat2f
- 2x2 single-precision matrix.
- Mat3d
- 3x3 double-precision matrix.
- Mat3f
- 3x3 single-precision matrix.
- Mat4d
- 4x4 double-precision matrix.
- Mat4f
- 4x4 single-precision matrix.
- Parametric
Planed - Double-precision parametric plane.
- Parametric
Planef - Single-precision parametric plane.
- Planed
- Double-precision plane.
- Planef
- Single-precision plane.
- Quatd
- Double-precision quaternion.
- Quatf
- Single-precision quaternion.
- Ray3d
- 3D double-precision ray.
- Ray3f
- 3D single-precision ray.
- Rectd
- Double-precision rectangle.
- Rectf
- Single-precision rectangle.
- Recti
- Integer rectangle.
- Segment2d
- 2D double-precision line segment.
- Segment2f
- 2D single-precision line segment.
- Segment3d
- 3D double-precision line segment.
- Segment3f
- 3D single-precision line segment.
- Vec2d
- 2D double-precision float vector.
- Vec2f
- 2D single-precision float vector.
- Vec2i
- 2D integer vector.
- Vec3d
- 3D double-precision float vector.
- Vec3f
- 3D single-precision float vector.
- Vec3i
- 3D integer vector.
- Vec4d
- 4D double-precision float vector.
- Vec4f
- 4D single-precision float vector.
- Vec4i
- 4D integer vector.