| Crates.io | spatial-math |
| lib.rs | spatial-math |
| version | 0.4.0-beta.1 |
| created_at | 2025-10-24 03:16:57.233664+00 |
| updated_at | 2025-10-24 03:16:57.233664+00 |
| description | Spatial math library for articulated body simulation |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1897942 |
| size | 111,242 |
A Rust implementation of spatial vector mathematics based on Roy Featherstone's rigid body dynamics algorithms. This library provides efficient, type-safe operations for articulated body simulation and robotics applications.
Spatial mathematics treats linear and angular quantities as unified 6-dimensional vectors, providing elegant and computationally efficient formulations for rigid body dynamics. The approach eliminates many of the complexities associated with traditional 3D vector calculations while maintaining physical correctness.
Based on Featherstone's spatial vector algebra from "Rigid Body Dynamics Algorithms" (2008), this library implements:
use spatial_math::*;
// Create spatial vectors
let velocity = SpatialMotionVector::from_array([1.0, 0.0, 0.0, // angular velocity ω
0.0, 1.0, 0.0]); // linear velocity v
let force = SpatialForceVector::from_array([0.0, 0.0, 1.0, // moment n
1.0, 0.0, 0.0]); // force f
// Create a transform
let transform = PluckerTransform::identity();
// Spatial vector operations
let power = velocity.dot(&force); // Power = v ⋅ f
let transformed_velocity = transform * velocity;
// Create rigid body inertia
let inertia = RigidBodyInertia::new(
2.0, // mass
vec3(0.0, 0.0, 1.0), // center of mass
SymmetricMat3::from_array([1.0, 0.0, 0.0, 1.0, 0.0, 1.0]) // inertia at CoM
);
// Calculate spatial force from motion
let spatial_force = inertia * velocity;
SpatialMotionVector: Spatial velocity (6×1 vector [ω, v])SpatialForceVector: Spatial force (6×1 vector [n, f])RigidBodyInertia: Rigid body spatial inertia (6×6 matrix)ArticulatedBodyInertia: Articulated body spatial inertia (6×6 matrix)PluckerTransform: Coordinate frame transformation (6×6 matrix)Pose: Position and orientation in 3D spaceSymmetricMat3: 3×3 symmetric matrix with compact storageVec3, Mat3: 3D vector and matrix typesUnitQuat: Unit quaternion for rotationsVec3Ext: Cross-product matrix conversionMatrixExt: NaN detection and matrix utilitiesViewMatrix: Memory-safe matrix viewsSpatialMotionVector = [ωx, ωy, ωz, vx, vy, vz]ᵀ
SpatialForceVector = [nx, ny, nz, fx, fy, fz]ᵀ
X = | E 0 |
| -E×r E |
where E is the 3×3 rotation matrix and r is the translation vector.
I = | I_3×3 m×r |
| r×m m |
where I_3×3 is the rotational inertia, m is mass, and r is center of mass position.
f64: Enable double precision floating point (default: f32)serde: Enable serialization/deserialization supportapprox: Enable approximate equality for testingThis project is licensed under the terms specified in the LICENSE file.
Contributions are welcome! Please ensure all code follows the existing style conventions and includes appropriate documentation for mathematical operations.