Struct MassProperties

Source
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

Source

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.

Source

pub fn mass(&self) -> f32

The finite, positive total mass.

Source

pub fn local_center_of_mass(&self) -> Vec3

The center of mass relative to the authored body origin.

Source

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.

Source

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

Source§

fn clone(&self) -> MassProperties

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MassProperties

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Copy for MassProperties

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.