Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove threshold in angular inertia eigenvalue calculation #209

Merged
merged 2 commits into from
Jun 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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