This chapter provides information on how to create basic 2D objects in Facet Modeler.
There are two types of compound 2D objects in Facet Modeler: profiles and contours. A contour is a set of segments, while a profile is an array of contours.
A segment, the basic part of a contour, is a curve given by two points and a
bulge value. If the bulge value is 0, the segment is a line. Otherwise, it is
a circular arc and its bulge equals tan(Angle/4)
.
To create a 2D object, you work with points and basically connect them. There
are several examples below. Some examples are a part of the Create
Basic Objects topic as some bodies are extruded or revolved from 2D profiles.
In the picture below you can see the distinction between a contour and a profile:
There are two ways to create a Profile2D object. The first way is to create
Contour2D objects first and then use the Profile2D()
constructor, inserting the created contours one by one, to create a profile
containing the previously mentioned contours. The second way is to create an
empty profile using the Profile2D()
default constructor and then create contours inside the profile. The first example
below demonstrates the first way, while the other example shows the second one.
Also, we have methods that create such contours as circle
and square.
The following code snippet creates a square with side length of dSide
by creating four points on a plane and connecting them:
Profile2D createSquare(const double dSide)
{
// Create a contour
Contour2D square;
// Set points that form a square
OdGePoint2dArray aPoints;
aPoints.reserve(4);
aPoints.push_back(OdGePoint2d(dSide, dSide));
aPoints.push_back(OdGePoint2d(dSide, 0.0));
aPoints.push_back(OdGePoint2d::kOrigin);
aPoints.push_back(OdGePoint2d(0.0, dSide));
// Insert points into the contour
square.appendVertices(aPoints);
// Form edges by connecting points and close the profile
square.setOrientationAt(0, efoFront);
square.setOrientationAt(1, efoFront);
square.setOrientationAt(2, efoFront);
square.setOrientationAt(3, efoFront);
square.setClosed();
// Make the contour outer by setting its direction counterclockwise
square.makeCCW();
return Profile2D(square);
}
The following code snippet creates a circle with radius of dRadius
:
Profile2D createCircle(const double dRadius)
{
// Create a profile
Profile2D profile;
// With one contour
profile.resize(1);
// Add first point with bulge == 1 (Arc)
profile.front().appendVertex(OdGePoint2d::kOrigin + OdGeVector2d::kXAxis * dRadius, 1);
// Add second point with bulge == 1 (Arc)
profile.front().appendVertex(OdGePoint2d::kOrigin - OdGeVector2d::kXAxis * dRadius, 1);
profile.front().setOrientationAt(0, efoFront);
profile.front().setOrientationAt(1, efoFront);
// Close contour
profile.front().setClosed();
// Make contour outer
profile.front().makeCCW();
return profile;
}
It's even easier to create profiles for squares and circles using our methods for contours.
In the demonstation below, a constructor of Profile2D
is used with our methods.
As for variables, center
is an OdGePoint2d
object, while dRadius
and dSide
are double
values.
Profile2D circle = Profile2D(Contour2D::createCircle(center, dRadius));
Profile2D square = Profile2D(Contour2D::createSquare(center, dSide));
To give you a better idea of how to create contours with multiple vertices in a more efficient way, there's a possible implementation of Contour2D createCircle(OdGePoint2d&, double)
method.
Contour2D createCircle(const OdGePoint2d& center, double dRadius)
{
const unsigned int iVrt = 2;
const OdGePoint2d aPoints[iVrt] = {
center - OdGeVector2d::kXAxis * dRadius,
center + OdGeVector2d::kXAxis * dRadius,
};
const double aBulges[iVrt] = { 1., 1. };
Contour2D result;
result.appendVertices(iVrt, aPoints, aBulges);
result.setClosed(); // Close profile
return result;
}
Facet Modeler also provides such classes as Contour3D
and Profile3D
. They represent Contour2D and Profile2D objects respectively with 3D transformation matrices applied to them.
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|