josegegas wrote: ↑Tue Sep 10, 2019 3:14 am
.Shape.Solids[0].MatrixOfInertia
This gives me three inertia moments (Ixx, Iyy and Izz) for the MBDyn simulation, but I don't really understand how these values are obtained. I mean, to calculate the inertia moments one needs the body's mass, but FreeCAD ignores the mass. What are the units of the values FreeCAD yields? How can I calculate these values including the object's mass? I am lost with this, and that is why I use my own code to calculate inertia moments. This works only for simple objects. If someone can guide me how to interpret the values FreeCAD gives me would be awesome!
First of all, you are replying to a single comment from mfasano, but you wrote four replies? Why?! You could have answered in a single reply; then you don't fragment the conversation into many posts, and it's easier to follow.
Now, with that said, let's go to the code.
FreeCAD uses the
Part Module (or Workbench) to expose the underlying "topological shapes" which are provided by the OpenCASCADE Technology (OCCT) libraries; in this case you want to get the properties of a Solid topological shape.
https://github.com/FreeCAD/FreeCAD/blob ... p.cpp#L150
The code of
src/Mod/Part/App/TopoShapeSolidPyImp.cpp implements the
Solid.MatrixOfInertia() method.
Code: Select all
Py::Object TopoShapeSolidPy::getMatrixOfInertia(void) const
{
GProp_GProps props;
BRepGProp::VolumeProperties(getTopoShapePtr()->getShape(), props);
gp_Mat m = props.MatrixOfInertia();
Base::Matrix4D mat;
for (int i=0; i<3; i++) {
for (int j=0; j<3; j++) {
mat[i][j] = m(i+1,j+1);
}
}
return Py::Matrix(mat);
}
As you can see, the matrix of inertia is itself calculated from an instance
props that calls its own
MatrixOfInertia() method. This
props is an instance of a class
GProp_GProps. We see at the top of the file the necessary import that provides this class,
# include <GProp_GProps.hxx>
It seems this header file is part of the OCCT sources. We can find its documentation online.
https://www.opencascade.com/doc/occt-7. ... props.html
Code: Select all
gp_Mat GProp_GProps::MatrixOfInertia() const
returns the matrix of inertia. It is a symmetrical matrix. The coefficients of the matrix are the quadratic moments of inertia.
| Ixx Ixy Ixz | matrix = | Ixy Iyy Iyz | | Ixz Iyz Izz |
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. It is possible to compute the matrix of inertia at another location point using the Huyghens theorem (you can use the method of package GProp : HOperator).
The same
TopoShapeSolidPyImp.cpp file defines other methods from the GProp class. You'd need to read more about these functions, and maybe there is the key to set the mass or density of your solid shape.
In particular the following seems relevant
Code: Select all
Standard_Real GProp_GProps::Mass() const
Returns the mass of the current system. If no density is attached to the components of the current system the returned value corresponds to :
* the total length of the edges of the current system if this framework retains only linear properties, as is the case for example, when using only the LinearProperties function to combine properties of lines from shapes, or
* the total area of the faces of the current system if this framework retains only surface properties, as is the case for example, when using only the SurfaceProperties function to combine properties of surfaces from shapes, or
* the total volume of the solids of the current system if this framework retains only volume properties, as is the case for example, when using only the VolumeProperties function to combine properties of volumes from solids. Warning A length, an area, or a volume is computed in the current data unit system. The mass of a single object is obtained by multiplying its length, its area or its volume by the given density. You must be consistent with respect to the units used.
I don't know the internals well enough, but it seems to me that there should be a way to define the density of a topological shape. Maybe it exists in OCCT but isn't exposed in FreeCAD, or maybe it is already there. For this I suggest asking Werner Meyer, one of the main FreeCAD developers, who probably knows more than anybody about OCCT with FreeCAD (except for maybe Jürgen Riegel, the original developer).
Since this is getting technical, maybe we should move the entire thread to the FEM subforum where it will get attention from other guys that know about physical simulations. Maybe one of them knows how to deal with this. In the case of finite element simulations (static and dynamic analysis), the density is added to objects when choosing a material, like general steel, aluminium, structural concrete, etc.