Constructing a Regular Polygon

The function

MbResultType RegularPolygon( const MbCartPoint &   centre,
                             const MbCartPoint &   point,
                                   size_t          vertexCount,
                                   bool            describe,
                                   MbCurve *&      result );

constructs a closed two-dimensional polyline representing a regular polygon inscribed in or circumscribed about a specified circle.

Input parameters of the function are:

  • centre - the center of the circle circumscribed about or inscribed in the regular polygon;

  • point - a point on the circle;

  • vertexCount - the number of polygon vertices;

  • describe - a flag determining the polygon’s position relative to the circle.

The output parameter of the function is the constructed curve result.

The function returns an operation result code from the enumeration MbResultType (see mb_operation_result.h).

The function is declared in the file action_curve.h.

Parameters centre and point define the circle in which the polygon with vertexCount vertices will be inscribed (describe = false) or about which the polygon with vertexCount vertices will be circumscribed (describe = true).

The vertexCount parameter defines the number of vertices of the regular polygon:

  • when vertexCount == 0, a circle with center centre passing through point is constructed;

  • when vertexCount == 1, a line segment with endpoints at centre and point is constructed;

  • when vertexCount == 2, a rectangle with sides parallel to the global axes and opposite vertices at centre and point is constructed, Fig. 1:

../../../../_images/M.3.5.3.png

Fig. 1

  • when vertexCount >= 3, a regular polygon with the specified number of sides is constructed.

The constructed curve is a closed polyline described in the paragraph Two-dimensional polyline MbPolyline. Figure 2 shows a regular polygon inscribed in a circle, and Fig. 3 shows a regular polygon circumscribed about a circle:

../../../../_images/M.3.5.1.png

Fig. 2

../../../../_images/M.3.5.2.png

Fig. 3

In the test application test.exe, construction of a regular polygon is performed via the menu command “Create→Curve on plane→By points→Polygon”.