JFLib

physics/src/mass.rs#

Source: lib/physics/src/mass.rs

mass -- the mass, the centre of mass and the inertia tensor of a shape of uniform density

Spheres, capsules and boxes in closed form; a convex hull from the tetrahedra between a point inside it
and its triangles (the second moment of a tetrahedron with one corner at the origin is
det / 120 (a a^T + b b^T + c c^T + s s^T), s = a + b + c), moved to the centre of mass with the
parallel axis theorem.  A mesh has none: it is static.
  • struct MassProps The mass of a body: how much (kg), where its centre is (in the shape's frame) and how it resists turning about that centre (the inertia tensor, kg m², in the shape's frame).
    • mass: f64 -- kg
    • center: Vec3 -- the centre of mass in the shape's frame
    • inertia: Mat3 -- the inertia tensor about the centre of mass, in the shape's frame

impl MassProps

  • const fn new(mass: f64, center: Vec3, inertia: Mat3) -> MassProps a mass mass at center with this inertia tensor
  • const fn point(mass: f64) -> MassProps a point mass at the origin that does not turn (an infinite inertia is no number: the tensor is 0 and a body reads 0 as "does not turn")
  • fn transformed(&self, iso: &Iso) -> MassProps the same body seen in the frame iso places it in (the centre moved, the tensor turned)
  • fn inertia_about(&self, p: Vec3) -> Mat3 the inertia tensor about another point (the parallel axis theorem), in the same frame
  • fn scaled(&self, factor: f64) -> MassProps the mass and tensor scaled by factor (another density)
  • fn is_valid(&self) -> bool mass, centre and tensor finite, the mass positive, the tensor symmetric with principal moments that are non-negative and keep the triangle inequality, in its own axes: what a solid body can have, of any size. Each principal moment is below the sum of the other two plus 1e-9 times the sum of all three (so the moments of a rod or a plate, which meet the inequality exactly, pass in any frame); the zero tensor of [MassProps::point] is valid.

impl Shape

  • fn mass_properties(&self, density: f64) -> Option<MassProps> the mass properties of the shape filled with density (kg/m³), None for a mesh (never dynamic), for a density that is not positive and finite and for sizes that are not (a radius, a box's half sizes; a capsule's half height may be 0)

Source: docs/API.md in the JFLib repository.