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 MassPropsThe 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-- kgcenter: Vec3-- the centre of mass in the shape's frameinertia: 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) -> MassPropsa massmassatcenterwith this inertia tensorconst fn point(mass: f64) -> MassPropsa 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) -> MassPropsthe same body seen in the frameisoplaces it in (the centre moved, the tensor turned)fn inertia_about(&self, p: Vec3) -> Mat3the inertia tensor about another point (the parallel axis theorem), in the same framefn scaled(&self, factor: f64) -> MassPropsthe mass and tensor scaled byfactor(another density)fn is_valid(&self) -> boolmass, 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 withdensity(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)