This chapter provides information on how to calculate volume for bodies and how to calculate area for profiles.
In Facet Modeler there are only two entity types that can have area and volume properties:
Profile2D and Body. Since a Profile2D object is two-dimensional and a Body object is three-dimensional, the methods of calculations are different.
As mentioned in the topic about profiles and contours, a profile is an array of contours.
That means it's possible to calculate a contour's area; to do that you can use the area() method.
The following code sample creates a square contour with side length dSide and calculates its area:
Contour2D squareContour = Contour2D::createSquare(OdGePoint2d::kOrigin, dSide);
// Calculate area of a contour
double contourArea = squareContour.area();
To calculate the area value for a Profile2D, use the signedArea() method:
double signedArea() const;
The following line calculates the area of a square profile with side length dSide:
Profile2D squareProfile = Profile2D(Contour2D::createSquare(OdGePoint2d::kOrigin, dSide));
// Calculate area of a profile
double profileArea = squareProfile.signedArea();
Since a body's face is technically a profile, you can also calculate its area using the area() method.
The following function calculates the face area of a given body by iterating through its faces and returns it as OdDouble. To get more information on iteration in Facet Modeler, see the corresponding topic.
And here you can see a possible usage of the created function on a box:
OdGeVector3d dimensionsBig = OdGeVector3d(50., 50., 50.);
Body bigBox = Body::box(OdGePoint3d::kOrigin, dimensionsBig);
// Calculate face area of a body
double surfaceArea = calcFaceArea(bigBox);