rapier
rapier copied to clipboard
Suspicious results from MassProperties algebra
I think there may be a bug somewhere in how MassProperties 'add' operations are handled in rapier3d 0.8.0.
See the following program:
use rapier3d::na::{Point3, Isometry3, Vector3};
use rapier3d::dynamics::MassProperties;
use rapier3d::math::AngVector;
#[test]
pub fn test_rapier_inertial_tensor_calculator() {
for p in vec![0.01, 100.0] {
let mut mass_points = Vec::new();
for z in vec![-50.0,50.0f32] {
mass_points.push(Point3::new(p*0.5, p*0.5, z));
mass_points.push(Point3::new(p*0.5, p*-0.5, z));
mass_points.push(Point3::new(p*-0.5, p*0.5, z));
mass_points.push(Point3::new(p*-0.5, p*-0.5, z));
}
let mut mass_prop = MassProperties::new(Point3::new(0.0,0.0,0.0), 1.0, AngVector::new(1e-3,1e-3,1e-3));
for p in mass_points.iter().copied() {
let mass_per_point = 1.0;
let mut point_mass_prop = MassProperties::new(Point3::new(0.0,0.0,0.0), mass_per_point, AngVector::new(1e-3, 1e-3, 1e-3));
point_mass_prop = point_mass_prop.transform_by(&Isometry3::new(p.coords, Vector3::new(0.0,0.0,0.0)));
mass_prop += point_mass_prop;
}
println!("p={}: MassProp: {:?}", p, mass_prop.inv_principal_inertia_sqrt); //The small difference for p = 0.01 and 100.0 is implausible
}
}
It outputs:
p=0.01: MassProp: Matrix { data: [[0.0056241076, 0.0069408445, 0.0060162893]] }
p=100: MassProp: Matrix { data: [[0.0034270522, 0.0037224356, 0.0034776148]] }
As the first object is like a very long thin rod, and the other is a fat box, I think there should be a larger difference between the two.
This is a simplified example. The background to this bug is that objects in my application are behaving in 'obviously' wrong ways, as if they have too high moments of inertia. I'm not an expert in mechanics, so it's entirely possible I've made a mistake somewhere.