Matrix of inertia with respect to a reference frame

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
sogartar
Posts: 1
Joined: Tue Jun 22, 2021 3:04 am

Matrix of inertia with respect to a reference frame

Post by sogartar »

I know I can get the matrix of inertia with respect to the global coordinate system with

Code: Select all

App.ActiveDocument.getObjectsByLabel("myobject")[0].Shape.MatrixOfInertia
I have a local coordinate system. How can I get the matrix of inertia with respect to that coordinate system?
edwilliams16
Veteran
Posts: 3180
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Matrix of inertia with respect to a reference frame

Post by edwilliams16 »

The "global" MOI is the moment of inertia of the object about its CG with coordinate axes aligned with the global system. If what you want is the MOI about its CG with respect to the local coordinate axes, this will do it:

Code: Select all

obj = App.ActiveDocument.getObjectsByLabel("myobject")[0]
globalRotMatrix = obj.getGlobalPlacement().Rotation.toMatrix()
globalmoiObj = obj.Shape.MatrixOfInertia
localmoiObj =  globalRotMatrix.transposed() * globalmoiObj * globalRotMatrix
If you actually wanted the MOI with respect to the coordinate origin, we'll need to add the parallel axes theorem contribution of the moment of the CG about the origin.

EDIT to include that contribution:

Code: Select all

def outerProduct(v1,v2):
    '''return outer product of two Vectors  v1_i*v2_j (4 x 4) Matrix'''
    m = App.Matrix(v1.x*v2.x, v1.x*v2.y, v1.x*v2.z, 0, v1.y*v2.x, v1.y*v2.y, v1.y*v2.z ,0, v1.z*v2.x, v1.z*v2.y, v1.z*v2.z,0, 0, 0, 0, 0)
    return m

obj = App.ActiveDocument.getObjectsByLabel("myobject")[0]
globalRotMatrix = obj.getGlobalPlacement().Rotation.toMatrix()
globalmoiObj = obj.Shape.MatrixOfInertia
localmoiObj =  globalRotMatrix.transposed() * globalmoiObj * globalRotMatrix
v = obj.Placement.Base
mass = obj.Shape.Mass
localFromOriginmoiObj = localmoiObj + outerProduct(mass * v, v)
App.Matrix could use a multiply by scalar method.
Post Reply