Skip to main content

phyz_math/
lib.rs

1//! Spatial algebra and math primitives for phyz physics engine.
2//!
3//! Implements 6D spatial vectors, Plücker transforms, and spatial inertia
4//! following Featherstone's conventions.
5
6pub mod quaternion;
7pub mod spatial;
8
9pub use quaternion::Quat;
10pub use spatial::{SpatialInertia, SpatialMat, SpatialTransform, SpatialVec};
11
12use nalgebra as na;
13
14/// 3D vector alias.
15pub type Vec3 = na::Vector3<f64>;
16/// 3x3 matrix alias.
17pub type Mat3 = na::Matrix3<f64>;
18/// 4x4 matrix alias.
19pub type Mat4 = na::Matrix4<f64>;
20/// 6D vector alias.
21pub type Vec6 = na::Vector6<f64>;
22/// 6x6 matrix alias.
23pub type Mat6 = na::Matrix6<f64>;
24/// Dynamic vector.
25pub type DVec = na::DVector<f64>;
26/// Dynamic matrix.
27pub type DMat = na::DMatrix<f64>;
28
29/// Cross-product matrix: [v]× such that [v]× w = v × w.
30#[inline]
31pub fn skew(v: &Vec3) -> Mat3 {
32    Mat3::new(0.0, -v.z, v.y, v.z, 0.0, -v.x, -v.y, v.x, 0.0)
33}
34
35/// Standard gravity (m/s²).
36pub const GRAVITY: f64 = 9.81;