How get center of mass of a closed wire or face ?

Hello,

I have to get the center point (barycenter) of a closed plane wire or of a face builder from this wire.
Is there any api that can do this ?

Thank you

Rob Bachrach's picture

Check out the BRepGProp class. The static functions fill in a GProp_GProps object with the mass properties.

Marco Balen's picture

Hello,

Thank for your answer,
I have tried the GProp_PGProps::Barycentre(Pnts,Density,Mass,Centre) method to approximate the solution using the vertex of the edge of the wire but I have the problem that the number of points from one side of the shape add a weight to this side of the shape moving the baricenter near the side.

Do you know a function that calculates the geometrical baricentre of a plane shape ?

Thank you

Rob Bachrach's picture

Have you just tried the GProp_GProps::CenterOfMass() function?

Marco Balen's picture

No , I haven't,

But I cannot undestand very well how can I use this function.
Can you provide me 3 sample line of code to use it with a wire or face ?

Rob Bachrach's picture

This example uses SurfaceProperties to compute the values for a face. In theory, you could use LinearProperties for a wire, but I have not tried it.

GProp_GProps massProps;
BRepGProp::SurfaceProperties(myShape, massProps);
gp_Pnt gPt = massProps.CentreOfMass();

Marco Balen's picture

Thank you Rob,

It works well on the face. I will try with the wire.

Thank you very much for the support,

Regards