Tuesday, March 13, 2012

Mass and geometry properties (my scratchpad)

Volume, center of mass and matrix of inertia

For all solids you can get:
  1. volume - add Shape.Volume attribute to object,
  2. center of mass - add Shape.CenterOfMass attribute,
  3. matrix of inertia - add Shape.MatrixOfInertia attribute.
Cone (height = 40 mm, radius = 30 mm) named "Revolution"

>>> App.ActiveDocument.getObject("Revolution").Shape.MatrixOfInertia
Matrix ((7.35133e+06,-6.48484e-11,2.72874e-09,0),(-6.48484e-11,7.35133e+06,4.02739e-10,0),(2.72874e-09,4.02739e-10,1.01788e+07,0),(0,0,0,1))
>>> App.ActiveDocument.getObject("Revolution").Shape.CenterOfMass
Vector (6.11835e-15, 6.99401e-16, 30)
>>> App.ActiveDocument.getObject("Revolution").Shape.Volume

MatrixOfInertia attribute output needs some explanation:
Returns the matrix of inertia. It is a symmetrical matrix.
The coefficients of the matrix are the quadratic moments of inertia.

 | Ixx Ixy Ixz 0 |
 | Ixy Iyy Iyz 0 |
 | Ixz Iyz Izz 0 |
 | 0 0 0 1 |

The moments of inertia are denoted by Ixx, Iyy, Izz.
The products of inertia are denoted by Ixy, Ixz, Iyz.
The matrix of inertia is returned in the central coordinate system (G, Gx, Gy, Gz) where G is the centre of mass of the system and Gx, Gy, Gz the directions parallel to the X(1,0,0) Y(0,1,0) Z(0,0,1) directions of the absolute cartesian coordinate system.
So, we have 3 moments of inertia:

Further explanation - FreeCAD forum.

Area of face

You can measure area of face, simply add Area attribute. If you need area of a sketch, convert one to a face:
>>> face = Part.Face(App.ActiveDocument.getObject("Sketch").Shape)
>>> face.Area

If you have a solid (eg. a Pad), select face or faces on the solid object, and use this script:

area = 0.0
for o in Gui.Selection.getSelectionEx() :
        for s in o.SubObjects:
                area = s.Area
                print "Area of selected face:" ,area


  1. I have a simple extruded box. When I go over a face: test.Pad.Face5 but I can't seem to find the command how to get the Area of that face.

  2. Post has been updated - check last script.

  3. >>> App.ActiveDocument.getObject("Cylinder").Shape.MatrixOfInertia
    Traceback (most recent call last):
    File "", line 1, in
    AttributeError: 'Part.TopoShape' object has no attribute 'MatrixOfInertia'

    After call matrixofinertia I get the Error and I don't know what to do. Please help me

  4. hi jaro , we are facing the same problem. do you have a solution ?
    thanks !

  5. Please install the latest FreeCAD. The issue is fixed now.
    Tested for version: 0.13.1766 (Git)

  6. Check also

  7. Hello!
    How can I get the volume (or mass) und the overall face of an imported STEP-file?

  8. Form volume, select object and:

    obj = FreeCADGui.Selection.getSelection()

    For area:

    area = 0.0
    for f in obj[0].Shape.Faces:
    area = f.Area + area
    print area

  9. hello, now from this example how can get the Mass moment of inertia ???
    please help