Skip to content

Commit

Permalink
fix: remove threshold in angular inertia eigenvalue calculation (#209)
Browse files Browse the repository at this point in the history
* fix: remove threshold in angular inertia eigenvalue calculation

* fix inertia matrix test to check the angular inertia instead of its inverse
  • Loading branch information
sebcrozet authored Jun 23, 2024
1 parent c82502c commit 62008d1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/mass_properties/mass_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl MassProperties {
let _ = principal_inertia_local_frame.renormalize();

// Drop negative eigenvalues.
let principal_inertia = eigen.eigenvalues.map(|e| if e < EPSILON { 0.0 } else { e });
let principal_inertia = eigen.eigenvalues.map(|e| e.max(0.0));

Self::with_principal_inertia_frame(
local_com,
Expand Down Expand Up @@ -510,7 +510,7 @@ impl approx::RelativeEq for MassProperties {
#[cfg(test)]
mod test {
use super::MassProperties;
use crate::math::Point;
use crate::math::{AngVector, Point};
#[cfg(feature = "dim3")]
use crate::math::{Rotation, Vector};
use crate::shape::{Ball, Capsule, Shape};
Expand Down Expand Up @@ -574,11 +574,15 @@ mod test {
assert_relative_eq!(m1m2m3 - m1 - m3, m2, epsilon = 1.0e-6);
assert_relative_eq!(m1m2m3 - m2 - m3, m1, epsilon = 1.0e-6);

// NOTE: converting the inverse inertia matrices don’t work well here because
// tiny inertia value originating from the subtraction can result in a non-zero
// (but large) inverse.
assert_relative_eq!(
((m1m2m3 - m1) - m2) - m3,
MassProperties::zero(),
(((m1m2m3 - m1) - m2) - m3).principal_inertia(),
AngVector::zero(),
epsilon = 1.0e-6
);
assert_relative_eq!((((m1m2m3 - m1) - m2) - m3).mass(), 0.0, epsilon = 1.0e-6);
}

#[test]
Expand Down

0 comments on commit 62008d1

Please sign in to comment.