Node: Regular Polygons Getstart, Next: Rectangles Getstart, Previous: Plane Figures, Up: Plane Figures
The following example creates a pentagon in the x-z plane, centered about the origin, whose enclosing circle has a radius equal to 3cm.
default_focus.set(2, 3, -10, 2, 3, 10, 10); Reg_Polygon p(origin, 5, 3); p.draw();
Fig. 20.
Three additional arguments cause the pentagon to be rotated about the x, y, and z axes by the amount indicated. In this example, it's rotated 90 degrees
about the x-axis, so that it comes to lie in the x-y plane:
Reg_Polygon p(origin, 5, 3, 90); p.draw();
Fig. 21.
In this example, it's rotated 36 degrees
about the y-axis, so that it appears to point in the opposite direction from the first example:
Reg_Polygon p(origin, 5, 3, 0, 36); p.draw();
Fig. 22.
In this example, it's rotated 90 degrees
about the z-axis, so that it lies in the z-y plane:
Reg_Polygon p(origin, 5, 3, 0, 0, 90); p.draw();
Fig. 23.
In this example, it's rotated 45 degrees
about the x, y, and z-axes in that order:
Reg_Polygon p(origin, 5, 3, 45, 45, 45); p.draw();
Fig. 24.
Reg_Polygons
need not be centered about the origin
. If
another Point
pt is used as the first argument, the Reg_Polygon
is first created with its center at the origin, then the specified
rotations, if any, are performed. Finally, the Reg_Polygon
is
shifted such that its center comes to lie on pt:
Point P(-2, 1, 1); Reg_Polygon hex(P, 6, 4, 60, 30, 30); hex.draw();
Fig. 25.
In the following example, the Reg_Polygon
polygon
is first
declared using the default constructor, which creates an empty
Reg_Polygon
. Then, the polygon
is repeatedly changed using
the setting function corresponding to the constructor used in the
previous examples. [next figure]
demonstrates that a given
Reg_Polygon
need not always have the same number of sides.
Point p(0, -3); Reg_Polygon polygon; for (int i = 3; i < 9; ++i) { polygon.set(p, i, 3); polygon.draw(); p.shift(0, 1); }
Fig. 26.