Group Abstract Group Abstract

Message Boards Message Boards

[?] Calculate moment of inertia from STL?

Posted 9 years ago
3 Replies

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!

Posted 9 years ago

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

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.

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