parry3d/mass_properties/
mass_properties_cone.rs1use crate::mass_properties::MassProperties;
2use crate::math::{Point, PrincipalAngularInertia, Real, Rotation, Vector};
3use na::RealField;
4
5impl MassProperties {
6 pub(crate) fn cone_y_volume_unit_inertia(
7 half_height: Real,
8 radius: Real,
9 ) -> (Real, PrincipalAngularInertia<Real>) {
10 let volume = radius * radius * Real::pi() * half_height * 2.0 / 3.0;
11 let sq_radius = radius * radius;
12 let sq_height = half_height * half_height * 4.0;
13 let off_principal = sq_radius * 3.0 / 20.0 + sq_height * 3.0 / 80.0;
14 let principal = sq_radius * 3.0 / 10.0;
15
16 (volume, Vector::new(off_principal, principal, off_principal))
17 }
18
19 pub fn from_cone(density: Real, half_height: Real, radius: Real) -> Self {
21 let (cyl_vol, cyl_unit_i) = Self::cone_y_volume_unit_inertia(half_height, radius);
22 let cyl_mass = cyl_vol * density;
23
24 Self::with_principal_inertia_frame(
25 Point::new(0.0, -half_height / 2.0, 0.0),
26 cyl_mass,
27 cyl_unit_i * cyl_mass,
28 Rotation::identity(),
29 )
30 }
31}