OpenSCAD User Manual/example module regular polygon()
Exmaple: regular_polygon() Module
A user defined module can generate the same shapes using some basic math and the polygon() module:
module regular_polygon(order = 4, r=1)
{ // default parameters give a unit square
// first divide 360 to make a vector of angles between vertices
angles=[ for (i = [0:order-1]) i*(360/order) ];
// use trigonometry to calculate Cartesian coordinates
coords=[ for (th=angles) [r*cos(th), r*sin(th)] ];
polygon(coords); // generate the polygon
}
regular_polygon(); // generate a default <code>regular_polygon</code>
Polygon shapes generated by circle() are drawn inscribed in a circle of the given radius, starting from a first point on the positive X axis.