Fix cylinder inertia tensor computation.
This commit is contained in:
@@ -4,27 +4,6 @@ use crate::geometry::Capsule;
|
|||||||
use crate::math::{Point, PrincipalAngularInertia, Rotation, Vector};
|
use crate::math::{Point, PrincipalAngularInertia, Rotation, Vector};
|
||||||
|
|
||||||
impl MassProperties {
|
impl MassProperties {
|
||||||
fn cylinder_y_volume_unit_inertia(
|
|
||||||
half_height: f32,
|
|
||||||
radius: f32,
|
|
||||||
) -> (f32, PrincipalAngularInertia<f32>) {
|
|
||||||
#[cfg(feature = "dim2")]
|
|
||||||
{
|
|
||||||
Self::cuboid_volume_unit_inertia(Vector::new(radius, half_height))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "dim3")]
|
|
||||||
{
|
|
||||||
let volume = half_height * radius * radius * std::f32::consts::PI * 2.0;
|
|
||||||
let sq_radius = radius * radius;
|
|
||||||
let sq_height = half_height * half_height * 4.0;
|
|
||||||
let off_principal = (sq_radius * 3.0 + sq_height) / 12.0;
|
|
||||||
|
|
||||||
let inertia = Vector::new(off_principal, sq_radius / 2.0, off_principal);
|
|
||||||
(volume, inertia)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn from_capsule(density: f32, a: Point<f32>, b: Point<f32>, radius: f32) -> Self {
|
pub(crate) fn from_capsule(density: f32, a: Point<f32>, b: Point<f32>, radius: f32) -> Self {
|
||||||
let half_height = (b - a).norm() / 2.0;
|
let half_height = (b - a).norm() / 2.0;
|
||||||
let (cyl_vol, cyl_unit_i) = Self::cylinder_y_volume_unit_inertia(half_height, radius);
|
let (cyl_vol, cyl_unit_i) = Self::cylinder_y_volume_unit_inertia(half_height, radius);
|
||||||
@@ -57,16 +36,4 @@ impl MassProperties {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "dim3")]
|
|
||||||
pub(crate) fn from_cylinder(density: f32, half_height: f32, radius: f32) -> Self {
|
|
||||||
let (cyl_vol, cyl_unit_i) = Self::cylinder_y_volume_unit_inertia(half_height, radius);
|
|
||||||
|
|
||||||
Self::with_principal_inertia_frame(
|
|
||||||
Point::origin(),
|
|
||||||
cyl_vol * density,
|
|
||||||
cyl_unit_i * density,
|
|
||||||
Rotation::identity(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
40
src/dynamics/mass_properties_cylinder.rs
Normal file
40
src/dynamics/mass_properties_cylinder.rs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
use crate::dynamics::MassProperties;
|
||||||
|
#[cfg(feature = "dim3")]
|
||||||
|
use crate::geometry::Capsule;
|
||||||
|
use crate::math::{Point, PrincipalAngularInertia, Rotation, Vector};
|
||||||
|
|
||||||
|
impl MassProperties {
|
||||||
|
pub(crate) fn cylinder_y_volume_unit_inertia(
|
||||||
|
half_height: f32,
|
||||||
|
radius: f32,
|
||||||
|
) -> (f32, PrincipalAngularInertia<f32>) {
|
||||||
|
#[cfg(feature = "dim2")]
|
||||||
|
{
|
||||||
|
Self::cuboid_volume_unit_inertia(Vector::new(radius, half_height))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "dim3")]
|
||||||
|
{
|
||||||
|
let volume = half_height * radius * radius * std::f32::consts::PI * 2.0;
|
||||||
|
let sq_radius = radius * radius;
|
||||||
|
let sq_height = half_height * half_height * 4.0;
|
||||||
|
let off_principal = (sq_radius * 3.0 + sq_height) / 12.0;
|
||||||
|
|
||||||
|
let inertia = Vector::new(off_principal, sq_radius / 2.0, off_principal);
|
||||||
|
(volume, inertia)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "dim3")]
|
||||||
|
pub(crate) fn from_cylinder(density: f32, half_height: f32, radius: f32) -> Self {
|
||||||
|
let (cyl_vol, cyl_unit_i) = Self::cylinder_y_volume_unit_inertia(half_height, radius);
|
||||||
|
let cyl_mass = cyl_vol * density;
|
||||||
|
|
||||||
|
Self::with_principal_inertia_frame(
|
||||||
|
Point::origin(),
|
||||||
|
cyl_mass,
|
||||||
|
cyl_unit_i * cyl_mass,
|
||||||
|
Rotation::identity(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@ mod mass_properties;
|
|||||||
mod mass_properties_ball;
|
mod mass_properties_ball;
|
||||||
mod mass_properties_capsule;
|
mod mass_properties_capsule;
|
||||||
mod mass_properties_cuboid;
|
mod mass_properties_cuboid;
|
||||||
|
mod mass_properties_cylinder;
|
||||||
#[cfg(feature = "dim2")]
|
#[cfg(feature = "dim2")]
|
||||||
mod mass_properties_polygon;
|
mod mass_properties_polygon;
|
||||||
mod rigid_body;
|
mod rigid_body;
|
||||||
|
|||||||
Reference in New Issue
Block a user