pub struct MassProperties { /* private fields */ }Expand description
Checked body-local mass and inertia, computed using the solver’s formulas.
The inertia is about the combined center of mass. Inspect a collider without inserting it into a world:
use ferravex_physics::{Collider, d3::ColliderBuilder};
let collider: Collider = ColliderBuilder::cuboid(1., 2., 3.).density(2.).into();
let properties = collider.try_mass_properties(false).unwrap();
assert_eq!(properties.mass(), 96.);
assert_eq!(properties.local_center_of_mass(), ferravex_math::Vec3::ZERO);
let (diagonal, off_diagonal) = properties.inertia();
assert_eq!(diagonal, ferravex_math::Vec3::new(416., 320., 160.));
assert_eq!(off_diagonal, ferravex_math::Vec3::ZERO);
let (inverse, _) = properties.inverse_inertia();
assert!((inverse.x * diagonal.x - 1.).abs() < 1e-6);Implementations§
Source§impl MassProperties
impl MassProperties
Sourcepub fn try_from_colliders<'a>(
children: impl Iterator<Item = &'a Collider> + Clone,
planar: bool,
) -> Result<MassProperties, MassPropertyError>
pub fn try_from_colliders<'a>( children: impl Iterator<Item = &'a Collider> + Clone, planar: bool, ) -> Result<MassProperties, MassPropertyError>
Compute a compound without allocating or mutating its colliders.
Uses at most two passes over the same ordered inputs; clones of the
iterator must yield the same colliders. At most crate::MAX_CHILDREN
children are accepted. Zero-density children contribute no mass; sensors
contribute normally, matching world insertion. planar selects area
density and Z-axis rotation instead of volume density and 3D rotation.
The 3D solver’s normalized determinant cutoff (1e-10) is retained.
Invalid geometry, nonfinite intermediate results, underflowed mass and unrepresentable reciprocals return a diagnostic. No input is clamped.
Sourcepub fn local_center_of_mass(&self) -> Vec3
pub fn local_center_of_mass(&self) -> Vec3
The center of mass relative to the authored body origin.
Sourcepub fn inertia(&self) -> (Vec3, Vec3)
pub fn inertia(&self) -> (Vec3, Vec3)
Symmetric inertia as (xx/yy/zz, xy/xz/yz) about the center of mass.
Only zz is active for planar bodies.
Sourcepub fn inverse_inertia(&self) -> (Vec3, Vec3)
pub fn inverse_inertia(&self) -> (Vec3, Vec3)
Inverse inertia as (xx/yy/zz, xy/xz/yz) in body-local coordinates.
Planar bodies have only zz; all other inverse entries are zero.
Trait Implementations§
Source§impl Clone for MassProperties
impl Clone for MassProperties
Source§fn clone(&self) -> MassProperties
fn clone(&self) -> MassProperties
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more