I want to let the user draw a complicated, 2D polyline, select it, and have it convert to a region so I can use the mass properties for a handful of tasks. I've gotten to the point (following the samples) where I am able to create the region using
es = AcDbRegion::createFromCurves(curveSegs, regions);
AcDbRegion *pRegion;
pRegion =static_cast<AcDbRegion*>(regions[0]); // I only have one element to pick
pRegion->getPlane(plane);
plane.getCoordSystem(origin, xAxis, yAxis);
es = pRegion->getAreaProp(origin, xAxis, yAxis, perimeter, area, centroid, momInertia,
prodInertia, prinMoments, prinAxes, radiiGyration, extentsLow, extentsHigh);
Then I save it to the database. It works fine up to this point, but I get the wrong centroid (and different than the command line "MASSPROP")
Anything obvious? Any help would be appreciated.
Thanks,
Ed
Solved! Go to Solution.
Solved by EMD1954. Go to Solution.
What are the actual values that you're passing for the origin, xAxis, and yAxis arguments to getAreaProp()? Perhaps the MASSPROP command uses the UCS instead of the World coordinate system.
Origin is -50.1250, 76.0000, 0.0000 (it's the first point of the 3Dpoly that i created before it's turned into a region)
xAxis is 1.0000, 0.0000, 0.0000
yAxis is 0.0000, 1.0000, 0.0000
Function is attached as .txt file
Thanks,
Ed
Try the WCS or UCS, then compare the results to MASSPROP.
Sorry for the trouble, but I don't understand. I tried it in the "world" UCS, changed the view and set the UCS to "View" and even tried to set the UCS to "element". What do you mean? Sorry.
I am referring to the first three arguments to getAreaProp(). For example, the WCS would be:
pRegion->getAreaProp(AcGePoint3d(0,0,0), AcGeVector3d(1,0,0), AcGeVector3d(0,1,0), ...);
Yes. The problem was that "origin" was returning the first point of the original polyline, so I just zeroed the X and Y coordinates (I need Z for the proper elevation). The xAxis and yAxis were correct:
pRegion->getPlane(plane);
plane.getCoordSystem(origin, xAxis, yAxis);
origin.x = 0.0;
origin.y = 0,0;
Works great - thank you,
Ed