A regular polygon is a polygon whose edges are all of equal length, and whose angles are all of equal size, and which is non-self-intersecting. (Alternatively, you can replace the last constraint with the constraint that the polygon be convex.)

Polygons which meet the first two properties but not the third are called stellated polygons.

For a regular polygon with n sides and sides of length s,

Perimeter = ns

Area = ns2 / 4 tan( pi / n )

In the spring of 2001 I spent a little time wondering about regular polygons and how to draw them, so I wrote a little PHP app to draw an arbitrary regular polygon. It works like this...

It turns out that you can construct a polygon of N vertices by starting with a polygon of N-1 vertices and then sticking a triangle onto it. Also remember that if some angle is composed of two adjacent angles, then the measure of the angle is equal to the sum of the measures of the adjacent angles. Finally, a polygon has to consist of at least 3 vertices (otherwise you'd be talking about a line segment or a point). So, the sum of the interior angles of a polygon of N vertices is equal to pi times N-2. Note: although the general public deals with degrees, the math is a lot easier to do in radians. So, for a regular polygon, the interior angles are all the same, and the measure of the interior angle is equal to (pi * N-2)/N.

Just about any graphics library will give you the ability to specify an array of points and call it a polygon, and all of them will let you draw a line between two points. So, I needed to figure out where on the coordinate plane the vertices lie. Say we draw a circle centered on the origin, of radius R. If we think of our regular polygon, we can think of the vertices as lying on the circle, and the sides as being chords. If we think of the plane in polar coordinates, then what we really need to do is find an angle, phi, which is (2 * pi)/N. Then for each vertex V[i] where i=0..N-1, the polar coordinate is (R, phi * i).

I wrote this in PHP, so the code looks like this:

```\$phi = (2 * M_PI)/\$N;
for (\$i=\$N-1; \$i>=0; \$i--)
{
\$theta = \$i * \$phi;
\$polar_vertices[\$i] = \$theta; // R is constant, so we don't need to store it
}
```

But very few graphics libraries will let you specify coordinates in polar form; they want you to give points in cartesian form. Fine -- the (x,y) pair that matches (R, theta) is (R * cos(theta), R * sin(theta)). And here's where doing all this in radians comes in handy -- because the trig functions don't work with degrees; they work with radians.

```for (\$i=\$N-1; \$i>=0; \$i--)
{
\$x_coord[\$i] = \$R * cos(\$polar_vertices[\$i]);
\$y_coord[\$i] = \$R * sin(\$polar_vertices[\$i]);
}
```

Now we've got a bunch of vertices, but the coordinates are centered on the origin. Now, maybe there's a graphics library out there somewhere that sets the origin at the middle of the drawing area, but the ones I've run into all set the origin at either the top left or bottom left of the drawing area, so that you only deal with positive coordinates. So, we have to do a further transformation of the coordinates -- shift 'em to the right and "up" so that the range of values, instead of going from -R to R, goes from 0 to 2*R.

```for (\$i=\$N-1; \$i>=0; \$i--)
{
\$x_coord[\$i] = (\$R * cos(\$polar_vertices[\$i])) + \$R;
\$y_coord[\$i] = (\$R * sin(\$polar_vertices[\$i])) + \$R;
}
```

In considering the relationship between radius and side length, consider how I draw the polygon; it's composed of a bunch of triangles, with the bases being the edges of the polygon and the apexes at the center. Each of those triangles is identical, and happens also to be isosceles. What this means is that if we draw the height, h, of one of these triangles (going from the apex at the center of the polygon to the base which is one of the polygon's sides) then we get two right triangles. The apex angle of the original triangle gets bisected, as does the base. The base angles of the original triangle are equal to half of the interior angle of the polygon. So, we know the measure of the base of the right triangle (half the side length) and the measure of the angles (since the angle measures derive from the number of vertices). Furthermore, if we knew the radius we could calculate the side length like this: (side / 2) = radius * sin(phi/2). Isolating the unknown (the radius) gives us the equation: radius = side / (2 * sin(phi/2)).

I once wrote a program for my graphic calculator based on the exact same logic described by sbeitzel above. However, because calculator BASIC doesn't support data types, it wasn't long before I tried entering fractional numbers of sides. The logic works just the same: the central angle is split into, say, 3.5 and then the program draws a 3.5-sided regular polygon! Something of a mathematical curiosity, so I investigated.

Say you enter 2.5 as the number of sides: write 2.5 as a fraction it's lowest terms, ie 5/2. Therefore, you will discover, the actually has five lines but it "goes round" twice. This is hard to describe without a picture, but fortunately, this case is exactly what it is known as a pentagram! Draw one for yourself, and you'll see what I mean. It has five lines, but it appears to complete two whole rotations. A shape with 2.25 sides is 9/4, so it has 9 lines and completes 4 rotations.

However, because we rely on writing the the number of sides as the ratio of two integers to discover the number of lines, what about numbers that cannot be written in this form: irrational numbers? Well, when you set the program to draw, for example, a pi-sided figure, it simply goes round and round forever, drawing an infinite number of lines, going round an infinite number of times, until the individual lines are lost in the realms of resolution and it looks like a slice through a torus. You could see this as the program trying to estimate the value of that irrational number with ever-more accurate fractions.

You can also enter negative values, but this doesn't yield anything quite so interesting; with my version of the program, it simply draws the lines in reverse order, finishing with a polygon just the same as with the absolute value of the number.

Just an interesting bit of geometry-related experimentation, showing what can be done with expanding a very simple concept. I'm still trying to get my head round the logical next extension: figures with complex numbers for their side count. Answers below if you have any insight on this.

Log in or register to write something here or to contact authors.