wolph / numpy-stl

Simple library to make working with STL files (and 3D objects in general) fast and easy.
http://numpy-stl.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
624 stars 105 forks source link

Intertia Matrix Issue / get_mass_properties wrong #120

Closed fdi438 closed 4 years ago

fdi438 commented 4 years ago

I've been trying to get an intertia matrix. The issues are:

For verification I tried the attached STL file (created with OpenSCAD). This is a block, size 10x10x20, centered at 0,0,0.

numpy-stl gives me:

Inertia matrix at expressed at the COG  = 
[83333.33333333    -0.            -0.        ]
[   -0.         83333.33333333    -0.        ]
[   -0.            -0.         33333.33333333]

However, based on my mechanics literature, the matrix should be:

m/12*(b²+c²) 0            0
0            m/12*(c²+a²) 0
0            0            m/12*(a²+b²)

which would result in (assuming m=1)

41.67  0      0
0      41.67  0
0      0      16.67

COG is correct (for this one only, for a sphere it's always slightly off), volume is also correctly calculated at 2000.

Here is the stl file (zipped so that I can upload it here). block_10-10-20.zip

The code to create it in OpenSCAD is cube([10,10,20],center=true);

fdi438 commented 4 years ago

Found the solution (after getting the same result in MeshLab).

The results are multiplied with the Volume, i.e. in my example it uses V=2000 for m (essentially assuming a density of 1 kg/m³).

As one does not specify any kind of mass or density for this function, I assumed that it is just left out = set to 1, which is obviously not the case.