## Tuesday, March 13, 2012

### 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.
Example:
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 37699.11184307751```

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:
Ixx=7.35133e+06
Iyy=7.35133e+06
Izz=1.01788e+07

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 1469.9597436001611```
```area = 0.0for o in Gui.Selection.getSelectionEx() :        for s in o.SubObjects:                area = s.Area                print "Area of selected face:" ,area ```