Message Boards Message Boards

[?] Calculate moment of inertia from STL?

Posted 7 years ago

I'm trying to make an STL analysis program for which I need to calculate the axis of minimum moment of inertia. The program so far can calculate the centre of mass and aligns the object such that its centre of mass is at the origin.

As some of you may know an STL is essentially a surface skin for which the assumption is placed that the enclosed volume is homogeneous (at least in my case). In a manner of speaking the data of an STL stores a model in the form of sets of three points which then can be used to produce a triangle, a large number of which are put together to make the complete surface. I exploited this fact when calculating the centre of mass by using the origin of the original file (which was likely not the centre of mass) as a fourth point for each set of three points, then calculating the volume using the scalar triple product as follows for each triangular face.

Volume of Tetrahedron formula

Which was then eventually used to calculate the true centre of mass for the entire object and this seems to work well.

This is a pretty open ended question but does anyone have any suggestions for how to implement calculating the axis of minimum moment of inertia? My initial thoughts are that I need to calculate a moment of inertia tensor matrix for which I need to calculate the moment of inertia of each element, similar to how I calculated the centre of mass, then combine it all through parallel axis theorem. From this matrix I can hopefully determine the axis of minimum moment of inertia for the object as well as the moment of inertial for various other axes. I am able to calculate the moment of inertia for an 'element' being a tetrahedron for one that has 3 of 4 faces orthogonal however this is not the case, we have 4 points one of which is an origin and 3 arbitrary ones.

Any thoughts, just spit-balling or otherwise would be appreciated.

Dan

3 Replies

Thanks Chris and Brad for your replies,

That is a lot of useful info, the eigenvector and value aspect is particularly useful, I thought it might be something along those lines but its been a good few years since I touched that stuff.

Just want to follow up on a few points. With the centroid command, does it average all the point data of the STL or actually compute the center of mass? For example if I have 2 faces of equal size yet one was divided into more triangular segments that biases the simple version of centroid that just considers just points and not an actual volume.

With the calculation of the moment of inertia tensor, I am trying to implement it myself in java so I am trying to work out the specific equations to use to turn the 3 points associated with an STL file facet and an origin (being also the center of mass) into the moment of inertia tensor.

Regarding an STL file example, I have only got simple primitives I've been testing my code on so-far where I know the answers already, such as rods around an axis, spheres, etc. The goal however is to take in 3D scan data of fruits and vegetables and have a consistent way to align them for comparing different species, such as length, width, volume, etc.

Hi Dan,

It would help if you distribute an example STL file. Your question may be answered using regions. See for example:

Integrate Regions

You may also need Eigensystem or Eigenvectors. Hope it helps.

Brad

Edit:

Following Christopher's example, we write a few expressions to make some connections to the type of expressions you would see in an undergrad physics textbook.

r = DiscretizeGraphics[ExampleData[{"Geometry3D", "SedanCar"}]];
Vol = Integrate[1, {x, y, z} \[Element] r];
COM = Integrate[#, {x, y, z} \[Element] r]/Vol & /@ {x, y, z};
Moments = 
  Outer[Integrate[#1 #2, {x, y, z} \[Element] r] &, {x, y, z} - 
    COM, {x, y, z} - COM];

Chop[Subtract[RegionCentroid[r], COM], 10^(-9)]
MomentOfInertia[r] // MatrixForm
Moments // MatrixForm

Out 1

The matrices are the same up to a multiple of the identity matrix, so we calculate the same eigenvectors:

Eigenvectors[  Moments ] // MatrixForm
Eigenvectors[  MomentOfInertia[r] ] // MatrixForm

Out 2

As for choosing the minimum, I think the mathematical definitions involve the corresponding eigenvalues. This math approach is useful to know in a few cases where the solid is nearly spherical or has approximate circular symmetry. In many cases, such as the example of a car, Christopher's common sense method of plotting the solid and looking for the long axis is the usual for physicists.

POSTED BY: Brad Klee

Hi Dan.

First, let's get a MeshRegion. We could use Import, but here I'm just going to use something from ExampleData.

r = DiscretizeGraphics[ExampleData[{"Geometry3D", "SedanCar"}]]

enter image description here

Next, it is easy to find the center of mass of this shape (assuming it is of uniform density). We can just use RegionCentroid.

In[]:= RegionCentroid[r]
Out[]= {-1.36011, 1.87744, 21.4279}

I believe that the axis around which this has the lowest moment of inertia is the eigenvector of the moment of inertia matrix with the lowest associated eigenvalue. We can compute that pretty easily, taking advantage of the fact that, according to its documentation page, "Eigenvectors with numeric eigenvalues are sorted in order of decreasing absolute value of their eigenvalues."

In[]:= Last[Eigenvectors[MomentOfInertia[r]]]
Out[]= {0.00163806, -0.999214, -0.0396081}

That should be the axis with the lowest moment of inertia. We can visualize all of this just to see if it is plausible.

Graphics3D[{
  EdgeForm[None], Opacity[0.2],
  MeshPrimitives[r, 2], 
  Opacity[1], Thick, Red, 
  InfiniteLine[RegionCentroid[r], Last[Eigenvectors[MomentOfInertia[r]]]],
  Blue, PointSize[Large], 
  Point[RegionCentroid[r]]}]

enter image description here

That looks plausible to me!

I hope that helps!

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract