parry2d/mass_properties/
mass_properties_triangle.rs1use crate::mass_properties::MassProperties;
2use crate::math::{Point, Real};
3use crate::shape::Triangle;
4
5impl MassProperties {
6 pub fn from_triangle(
8 density: Real,
9 a: &Point<Real>,
10 b: &Point<Real>,
11 c: &Point<Real>,
12 ) -> MassProperties {
13 let triangle = Triangle::new(*a, *b, *c);
14 let area = triangle.area();
15 let com = triangle.center();
16
17 if area == 0.0 {
18 return MassProperties::new(com, 0.0, 0.0);
19 }
20
21 let ipart = triangle.unit_angular_inertia();
22
23 Self::new(com, area * density, ipart * area * density)
24 }
25}