Close

Relief for ODA Team in Ukraine

Learn more
ODA Facet Modeler
Calculate Area and Volume

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.

Profile2D

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.


OdDouble calcFaceArea(Body& body)
{
  FacetModeler::FaceIterator iterator(&body);
  OdDouble faceArea = 0;
  for (; !iterator.done(); iterator.next())
  {
    faceArea += iterator.get()->area();
  }
  return faceArea;
}

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);

Body

To calculate the volume value for a body, use the volume() method:

double volume() const;

The following code fragment creates a box and calculates its volume:


OdGeVector3d dimensionsSmall = OdGeVector3d(10., 10., 10.);
Body smallBox = Body::box(OdGePoint3d::kOrigin, dimensionsSmall);
// Calculate volume of a body
double boxVolume = smallBox.volume();

See Also

Work With B-Rep Data in Facet Modeler
Create Basic Objects
Create Basic 2D Objects
Create Objects via Revolution
Create Objects via Extrusion
Iterate through Entities
Perform Boolean Operations
Perform Slicing Operations
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.