center of gravity

Anybody know how to get center of gravity from TopoDS_Shape?

for instance

for(; Start shape; end shape)
SumOfXdistance += Anyfunction(subShapecordianteX);
SumOfYdistance += Anyfunction(subShapecordianteY);
SumOfZdistance += Anyfunction(subShapecordianteZ);

centerOfgravityX = SumOfXdistance / (any number of shapes or volume or etc..)
centerOfgravityY = SumOfYdistance / (any number of shapes or volume or etc..)
centerOfgravityZ = SumOfZdistance / (any number of shapes or volume or etc..)

looks like this, SUM_CofG = SUB_GofG / numberOfSubObject
or I think it can be some method by using integral calculus.

I think it is sure it is.
could you help me how to make this from shpes.

Thomas Paviot's picture

Hi Mathing,

The following python script will answer your question.

# first create a TopoDS_Shape
cube_shape = BRepPrimAPI_MakeBox(50.,50.,50.).Shape()
# Compute inertia properties
props = GProp_GProps()
# Get inertia properties
mass = props.Mass()
cog = props.CentreOfMass()
matrix_of_intertia = props.MatrixOfInertia()
# Display inertia properties
print "Cube mass=%s"%mass
print "Center of mass:%s"%cog.Coord().__str__()

Best Regards,