# Regular polygon equation (solved)

So I’ve finally solved this. You can read about the background and context for the question on:

This is the Wolfram Alpha friendly command:
polarplot [ cos(Pi/7)/cos( | (t mod (2Pi/7)) – (2Pi/(2*7)) | ) , {t,0,2Pi}]

That will generate a regular polygon with 7 sides, with a circumradius of 1 unit. Substitute all the 7’s with the number of sides you want and voila! And the general equation is thus:

cos(Pi/N) / cos( ABS( (t mod (2Pi/N)) – (2Pi/(2*N)) ) )

where t is in [0,2Pi], and N is the number of sides

So how did I get the equation?

The formula for the apothem is cos(Pi/N). The apothem is the shortest distance from the centre to the side. With that, I bring your attention to this illustration. (this is a regular polygon with 4 sides. “It’s a square!”. Yes, I know) The length “A” is the apothem, and t is the angle running in the equation we stated above. “apm” is the angle the apothem (for this particular segment of t) makes with the positive X axis.

And L is what we want to find.

We will define the first segment as the segment immediately after the segment whose apothem lies on the positive X axis. (so the apothem illustrated above is for the first segment) That will uniquely identify our segments.

Now convince yourself that the angle apm is in multiples of 2PI/N radians.

To find L, we need to find the angle s (I’m running out of colours…). And angle s = t – apm.

So s = t – 2PI/2N

“But that’s not exactly right!” you say. And you’re right. Because that didn’t take care of the multiples of 2PI/N radians thing.

To get the working t angle we’re using, it should be

“working t angle” = t modulus 2PI/N

Convince yourself that’s true. Substitute N with 4 or 5 or 100.

“But that’s not exactly right!” you say. And you’re right.

Because s = “working t angle” – 2PI/2N
can be negative (suppose the red line L is on the right side of A). That’s why we have

s = ABS( (t modulus 2PI/N) – 2PI/2N )

Why do we need to find s again? Because we want to find L. And L can be found with this equation:

A/L = cos(s)

Revise your trigonometry rules. Cosine of the acute angle is equal to adjacent side divide by the hypotenuse.

So L = A/cos(s)
= cos(PI/N) / cos(ABS( (t modulus 2PI/N) – 2PI/2N ))

So why do we need to find L again? In polar coordinates, you only need the angle and the radius (or length from origin) to uniquely determine a point. Since we have the angle, we just need the radius (or length).

That’s why the polar plotting from Wolfram Alpha works.

You can probably convert that from a polar coordinate point equation representation to a Cartesian point equation representation, but I’m done for now.