How to correctly calculate center of mass for an ellipse

b_walter's picture

I am new to opencascade and I try to add an ellipse to cadquery (https://github.com/CadQuery/cadquery), a python lib using pythonocc. The way it works is that the ellipse is created, however the center not saved.
Later in the modelling process, if you want to start from the center of the ellipse, it will be calculated by using the centerOfMass property.

I tried to translate the python approach to C++ and added an optimal bounding box to show that the ellipse is in fact centered around (0,0,0):


gp_Pnt center(0., 0., 0.);
gp_Dir zDir = gp::DZ();
gp_Ax2 axis(center, zDir);
gp_Elips ellipse_gp(axis, 4000., 40.);
TopoDS_Edge ellipse = BRepBuilderAPI_MakeEdge(ellipse_gp);
//
double xmin, ymin, zmin, xmax, ymax, zmax;
Bnd_Box bb;
BRepBndLib::AddOptimal(ellipse, bb);
bb.Get(xmin, ymin, zmin, xmax, ymax, zmax);
printf("ellipse (bb x): [%12.6f, %12.6f]\n", xmin, xmax);
printf("ellipse (bb y): [%12.6f, %12.6f]\n", ymin, ymax);
printf("ellipse (bb z): [%12.6f, %12.6f]\n", zmin, zmax);
//
GProp_GProps Properties;
BRepGProp::LinearProperties(ellipse, Properties);
gp_Pnt c = Properties.CentreOfMass();
printf("ellipse (center): %9.6f %9.6f %9.6f\n", c.X(), c.Y(), c.Z());

While I would expect the center of mass to be (0,0,0), the result is different:


ellipse (bb x): [-4000.000000, 4000.000000]
ellipse (bb y): [ -40.000000, 40.000000]
ellipse (bb z): [ 0.000000, 0.000000]
ellipse (center): -81.295066 0.000000 0.000000

What would be the correct way to create an ellipse and retrieve the correct center of mass later?

www.opencascade.com

Copyright 2011-2019
OPEN CASCADE SAS
Contact us