aboutsummaryrefslogtreecommitdiff
path: root/src/dynamics/mass_properties_cuboid.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2020-08-25 22:10:25 +0200
committerSébastien Crozet <developer@crozet.re>2020-08-25 22:10:25 +0200
commit754a48b7ff6d8c58b1ee08651e60112900b60455 (patch)
tree7d777a6c003f1f5d8f8d24f533f35a95a88957fe /src/dynamics/mass_properties_cuboid.rs
downloadrapier-754a48b7ff6d8c58b1ee08651e60112900b60455.tar.gz
rapier-754a48b7ff6d8c58b1ee08651e60112900b60455.tar.bz2
rapier-754a48b7ff6d8c58b1ee08651e60112900b60455.zip
First public release of Rapier.v0.1.0
Diffstat (limited to 'src/dynamics/mass_properties_cuboid.rs')
-rw-r--r--src/dynamics/mass_properties_cuboid.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/dynamics/mass_properties_cuboid.rs b/src/dynamics/mass_properties_cuboid.rs
new file mode 100644
index 0000000..2d870cf
--- /dev/null
+++ b/src/dynamics/mass_properties_cuboid.rs
@@ -0,0 +1,33 @@
+use crate::dynamics::MassProperties;
+use crate::math::{Point, PrincipalAngularInertia, Vector};
+
+impl MassProperties {
+ pub(crate) fn cuboid_volume_unit_inertia(
+ half_extents: Vector<f32>,
+ ) -> (f32, PrincipalAngularInertia<f32>) {
+ #[cfg(feature = "dim2")]
+ {
+ let volume = half_extents.x * half_extents.y * 4.0;
+ let ix = (half_extents.x * half_extents.x) / 3.0;
+ let iy = (half_extents.y * half_extents.y) / 3.0;
+
+ (volume, ix + iy)
+ }
+
+ #[cfg(feature = "dim3")]
+ {
+ let volume = half_extents.x * half_extents.y * half_extents.z * 8.0;
+ let ix = (half_extents.x * half_extents.x) / 3.0;
+ let iy = (half_extents.y * half_extents.y) / 3.0;
+ let iz = (half_extents.z * half_extents.z) / 3.0;
+
+ (volume, Vector::new(iy + iz, ix + iz, ix + iy))
+ }
+ }
+
+ pub(crate) fn from_cuboid(density: f32, half_extents: Vector<f32>) -> Self {
+ let (vol, unit_i) = Self::cuboid_volume_unit_inertia(half_extents);
+ let mass = vol * density;
+ Self::new(Point::origin(), mass, unit_i * mass)
+ }
+}