VolumeMoments in C#

I’m looking for a way to get the principal moments of inertia and principal axis about the centroid axes of a Brep/Mesh in C# to use in a Grasshopper component.

In Rhino I can use the VolumeMoments command to get this information but I’m not able to find a corresponding API function. There is the VolumeMassProperties class which provides most of the info given by the VolumeMoments command but i can’t see the properties that I need. I the property missing? How could I get the principal axis

See you

To calculate the properties you need to call the Compute() method on the VolumeMassProperties.

var vp = VolumeMassProperties.Compute(shape, true, true, true, true);
// You now have access to vp.Centroid, vp.WorldCoordinatesFirstMoments, etc.

Hi David,
thanks for your reply.

Yes, I called Compute() and I do have access to the properties, but as fare as I can see the principal moments and principal axis for volumes are missing. The corresponding calls for areas (AreaMassProperties) features these principle moments as a property but the volume class dose not, does it?

Thanks to Mahdiyar’s post in Ghpython executing rhino command and get the result inside grasshopper? I can get the output of the VolumeMoments command and parse that, but that does not seam to be the most elegant solution.

See you

There’s a bunch of Vector3d properties on VolumeMassProperties… however if all of them are something other than what you’re looking for you may have to post a request on the Rhino Developer category.


If you go to the api documentation (RhinoCommon)

I believe these are the coordinates you’re looking for:

Hi Ivelin,
thank for checking he documentation but these are the moments listed as ‘Volume Moments of Inertia about Centroid Coordinate Axes’ by the VolumeMoments command I’m looking for the ‘Volume Principal Moments of Inertia about Centroid and Principal Axes’. I think the API is missing this info.

See you

Well Florian,

My memories from the university when we studied that aren’t strong but according to this:
and this:

This is exactly what you’re asking for

the thing that I marked on the picture should be enough for you to calculate the directions of the principal axes.

Or perhaps there is a way to get the matrix and derive the directions from there.

I’m not near a practice workstation right now … so get what’s available at home (not much, mind).

Brep_MomentsOfInetria_V1.3dm (218.4 KB)
Brep_MomentsOfInetria_V1.gh (126.1 KB)

Hi Peter,
wow, did you just write this. I’ll take a closer look later.

Meanwhile I put together a crude, semi-working, python script extracting the information of interest from the output of the VolumeMoments command:

VolumeMassProperties_Test_0.gh (7.6 KB)

See you

1 Like