# Is there an equation to describe regular polygons?

For example, the square can be described with the equation $|x| + |y| = 1$. So is there a general equation that can describe a regular polygon (in the 2D Cartesian plane?), given the number of sides required?

Using the Wolfram Alpha site, this input gave an almost-square: PolarPlot(0.75 + ArcSin(Sin(2x+Pi/2))/(Sin(2x+Pi/2)*(Pi/4))) (x from 0 to 2Pi)

This input gave an almost-octagon: PolarPlot(0.75 + ArcSin(Sin(4x+Pi/2))/(Sin(4x+Pi/2)*Pi^2)) (x from 0 to 2Pi)

The idea is that as the number of sides in a regular polygon goes to infinity, the regular polygon approaches a circle. Since a circle can be described by an equation, can a regular polygon be described by one too? For our purposes, this is a regular convex polygon (triangle, square, pentagon, hexagon and so on).

It can be assumed that the centre of the regular polygon is at the origin $(0,0)$, and the radius is $1$ unit.

If there's no such equation, can the non-existence be proven? If there are equations, but only for certain polygons (for example, only for $n < 7$ or something), can those equations be provided?

-
This was actually asked by a blog reader. He read this blog post of mine and wondered about generalising the question to include regular polygons. –  Vincent Tan May 29 '11 at 11:48
The answer depends on what kind of functions you're allowing in such an equation. –  Qiaochu Yuan May 29 '11 at 12:08
If you can use rotation matrices then I would assume its possible... –  soandos May 29 '11 at 12:17
Qiaochu, any function can be used. As long as the resulting polygon is continuous (no breaks) and defined using that one equation. –  Vincent Tan May 29 '11 at 15:13

Any polygon (regular or not) can be described by an equation involving only absolute values and polynomials. Here is a small explanation of how to do that.

Let's say that a curve $C$ is given by the equation $f$ if we have $C = \{(x,y) \in \mathbb{R}^2, \, f(x,y) = 0\}$.

• If $C_1$ and $C_2$ are given by $f_1$ and $f_2$ respectively, then $C_1 \cup C_2$ is given by $f_1 . f_2$ and $C_1 \cap C_2$ is given by $f_1^2 + f_2^2$ (or $|f_1| + |f_2|$). So if $C_1$ and $C_2$ can be described by an equation involving absolute values and polynomials, then so do $C_1 \cup C_2$ and $C_1 \cap C_2$.

• If $C = \{(x,y) \in \mathbb{R}^2, \, f(x,y) \ge 0\}$, then $C$ is given by the equation $|f|-f$.

Now, any segment $S$ can be described as $S = \{(x,y) \in \mathbb{R}^2, \, a x + b y = c, \, x_0 \le x \le x_1, \, y_0 \le y \le y_1\}$, which is given by a single equation by the above principles. And since union of segments also are given by an equation, you get the result.

EDIT : For the specific case of the octagon of radius $r$, if you denote $s = \sin(\pi/8)$, $c = \cos(\pi/8)$, then one segment is given by $|y| \le rs$ and $x = rc$, for which an equation is

$$f(x, y) = \left||rs - |y|| - (rs - |y|)\right| + |x-rc| = 0$$

So I think the octagon is given by

$$f(|x|,|y|) \ f(|y|,|x|) \ f\left(\frac{|x|+|y|}{\sqrt{2}}, \frac{|x|-|y|}{\sqrt{2}}\right) = 0$$

To get a general formula for a regular polygon of radius $r$ with $n$ sides, denote $c_n = \cos(\pi/n)$, $s_n = \sin(\pi/n)$ and

$$f_n(x+iy) = \left||rs_n - |y|| - (rs_n - |y|)\right| + |x-rc_n|$$

then your polygon is given by

$$\prod_{k = 0}^{n-1} f_n\left(e^{-\frac{2 i k \pi}{n}} (x+iy)\right) = 0$$

Depending on $n$, you can use symmetries to lower the degree a bit (as was done with $n = 8$).

-
Hi Joel, can this result be used to generate some equations for regular polygons? tx –  Arjang May 29 '11 at 12:40
@Arjang : Yes, I think this principle gives you a single equation for polygons. In fact more generally, if you have a set that is described by any number of inequalities, linked by any number of logical "and" and "or", you can write it in a single equation. –  Joel Cohen May 29 '11 at 12:54
Hi Joel, can an equation be formulated that depends on the number of sides of a polygon? The mathematical formulation is sound. It's just that as the number of sides go up, the equation gets a lot of unions tacked on. –  Vincent Tan May 29 '11 at 15:11
@ Vincent : I added a general formula for any $n$ in the answer (not sure if that is what you're looking for). –  Joel Cohen May 29 '11 at 16:06
For an algorithm for getting a boolean formula for a polygon, see An efficient algorithm for finding the CSG representation of a simple polygon. –  lhf May 29 '11 at 20:06

Here's a parametric equation I have made for a regular $n$-gon, coded in R:

n=5;
theta=(0:999)/1000;
r=cos(pi/n)/cos(2*pi*(n*theta)%%1/n-pi/n);
plot(r*cos(2*pi*theta),r*sin(2*pi*theta),asp=1,xlab="X",ylab="Y",
main=paste("Regular ",n,"-gon",sep=""));


And picture:

The formula I used is

$$\displaystyle r=\frac{\cos\left(\frac{\pi}{n}\right)}{\cos\left(\left(\theta \mod \frac{2\pi}{n}\right) -\frac{\pi}{n}\right)} \; .$$

This equation is actually just the polar equation for the line through the point $(1,0)$ and $(\cos(2\pi/n),\sin(2\pi/n))$ which cointains one of the edges. By restricting the range of the variable $\theta$ to the interval $[0,2\pi/n[$, you will in fact just get that edge. Now, we want to replicate that edge by rotating it repeatedly through an angle $2\pi/n$ to get the full polygon. But this can also be achieved by using the modulus function and reducing all angles to the interval $[0,2\pi/n[$. This way, you get the polar equation I propose.

So, using polar plots and the modulo function, it's pretty easy to make regular n-gons.

-
Hi Raskolnikov, can you explain how you got (or derived) that formula? –  Vincent Tan May 29 '11 at 15:15
@Vincent Tan: I added a short explanation. –  Raskolnikov May 29 '11 at 15:39
I think this looks neater than Joel's construct. Too bad this isn't the accepted answer... –  Ｊ. Ｍ. Jul 29 '11 at 4:35
Here's an interactive demo of Raskolnikov's answer: geogebratube.org/student/m157867 –  murkle Sep 22 at 9:06

The following is probably not in the spirit of the game, but what about a parametric equation? If we are willing to use complex numbers to represent points in the plane, we could use $$z=t\exp(2\pi ik/n) +(1-t)\exp(2\pi i(k+1)/n),\qquad 0 \le t<1,\quad k=0, 1, \dots, n-1$$

-
Parametric equations are fine. We can broaden the scope so that if a few equations are needed, that's still fine. But only as many as needed. For example, in 2D Cartesian, if 2 equations can completely represent a polygon (probably corresponding to x and y), then it's still usable. –  Vincent Tan May 29 '11 at 15:21

Here is another parametric equation for a regular $n$-gon with unit radius:

\begin{align*}x&=\cos\left(\frac{\pi}{n}\right)\cos\left(\frac{\pi}{n}(2\lfloor u\rfloor+1)\right)-(2u-2\lfloor u\rfloor-1)\sin\left(\frac{\pi}{n}\right)\sin\left(\frac{\pi}{n}(2\lfloor u\rfloor+1)\right)\\y&=\cos\left(\frac{\pi}{n}\right)\sin\left(\frac{\pi}{n}(2\lfloor u\rfloor+1)\right)+(2u-2\lfloor u\rfloor-1)\sin\left(\frac{\pi}{n}\right)\cos\left(\frac{\pi}{n}(2\lfloor u\rfloor+1)\right)\end{align*}

for $0 \leq u \leq n$.

The provenance of this set is a bit more transparent if we switch to matrix-vector notation:

$$\begin{pmatrix}\cos\left(\frac{\pi}{n}(2\lfloor u\rfloor+1)\right)&-\sin\left(\frac{\pi}{n}(2\lfloor u\rfloor+1)\right)\\\sin\left(\frac{\pi}{n}(2\lfloor u\rfloor+1)\right)&\cos\left(\frac{\pi}{n}(2\lfloor u\rfloor+1)\right)\end{pmatrix}\begin{pmatrix}\cos\left(\frac{\pi}{n}\right)\\(2u-2\lfloor u\rfloor-1)\sin\left(\frac{\pi}{n}\right)\end{pmatrix}$$

and we see that the construction involves rotating and copying the line segment joining the points $(\cos\left(\frac{\pi}{n}\right),\pm\sin\left(\frac{\pi}{n}\right))$ $n$ times around a circle.

Here's sundry Mathematica code:

GraphicsGrid[Partition[Table[
ParametricPlot[Through[{Re, Im}[
(Cos[Pi/n] + I (2u - 2 Floor[u] - 1)Sin[Pi/n])*
Exp[(I Pi/n) (2 Floor[u] + 1)]],
{u, 0, n}], {n, 3, 11}], 3]]


-

Reposted from PolymathProgrammer.com, my answer to my own initial query. Generated mostly on my own after some initial help from a friend (Jason Schmurr) and my dad (Russell Gmirkin)

I believe I've solved my own inquiry. The following are functions that, when graphed in polar coordinates render lovely polygons.

In fact, I’ve got 3 versions (6 if you consider rotation a factor; to either align a vertex or the midpoint of a side with $\theta=0$). One with circumradius = 1 (as vertices $\to \infty$, polygons expand outward toward the circumscribed circle), one with apothem = 1 (as vertices $\to \infty$, polygons collapse inward toward the inscribed circle) and one with the midpoint between circumradius & apothem = 1 (as vertices $\to \infty$, both the maxima and minima, thus the circumscribed and inscribed circles, collapse toward that ‘midpoint radius’).

I’d be interested to know whether this approach, describing the radius of a polygon as a periodic function, has any precedent (has anyone else done this, or am I the first)? I’ve been working on this idea for some time (on and off for years), but just recently overcame some stumbling blocks with a little help from a friend and my dad. Most of the legwork was my own, though.

The relatively final form(s) appear to be:

1/(((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[(v*x)/4]]+((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)-(Pi/2)]]-((Sec[pi/v]-1)/(Sec[Pi/4]-1))+1)

(n-gon, circumradius=1, rotated $-\pi/4$)
1/(((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)-(Pi/4)]]+((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)-(3Pi/4)]]-((Sec[pi/v]-1)/(Sec[Pi/4]-1))+1)

(n-gon, function centered around unit circle, unrotated)
((Sec[Pi/v]+1)/2)/(((Sec[Pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)]]+((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)-(Pi/2)]]-((Sec[pi/v]-1)/(Sec[Pi/4]-1))+1)

(n-gon, function centered around unit circle, rotated $-\pi/4$)
((Sec[Pi/v]+1)/2)/(((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)-(Pi/4)]]+((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)-(3Pi/4)]]-((Sec[pi/v]-1)/(Sec[Pi/4]-1))+1)

(n-gon, apothem=1, unrotated)
Sec[Pi/v]/(((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[(v*x)/4]]+((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)-(Pi/2)]]-((Sec[pi/v]-1)/(Sec[Pi/4]-1))+1)

(n-gon, apothem=1, rotated $-\pi/4$)
Sec[Pi/v]/(((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)-(Pi/4)]]+((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)-(3Pi/4)]]-((Sec[pi/v]-1)/(Sec[Pi/4]-1))+1)

Don’t know whether they simplify at all to something less complicated… Even if not, they’re beauties!

Examples:

3-gon: here

4-gon: here

5-gon: here

If it's a unique solution and I'm first to it, I submit these as the Gmirkin Polygon Radius Function(s) (or some suitably nifty sounding name that’s not too cumbersome). *Smile* Heh.

I may write them up formally for publication at some point, once a few previous engagements clear up, assuming they’ve not previously been published or some directly correlated function has already been published elsewhere. (If so, I’d like to know when, where and by whom; for academic curiosity’s sake.)

It is my belief that a similar function exists for describing 3D Polyhedrons of some description(s). Though, I have not yet even attempted such a case and will probably stick to 2D cases for now. I can also tell you that if you vary the phase shift of the denominator [Abs[Cos[]]] terms by differing amounts (though not both by some multiple of $\pi/4$, $\pi/2$, etc.), you can also reproduce rectangles, isosceles triangles, etc. In some cases you can also generate diamond shapes by varying some other parameters. It's s surprisingly robust solution, as I'd hoped. Lord knows it's taken me a few years of false starts to get at the correct combination of functions. Though, I learned plenty along the way, much of which helped me generalize to all polygons from the square case a friend solved at my behest a week or two ago.

Here's hoping this is an interesting, unique new solution that's viable and notable. (One can hope!)

Sorry the post is a bit lengthy... ;)

Best,
~Michael Gmirkin

Edit:

Sorry. Jumped the gun slightly.

I retract the above equations. At the behest of someone on another site, I checked in Wolfram Alpha at a few data points. While it appears to work for the Square case (where the coefficients and corrective term basically cancel out), it doesn't work for other cases, but is slightly off. I think I've got the coefficients wrong. Will have to poke around a bit more in the maths to see if it's possible to get a technically correct exact solution.

The graphs were so close as to fool me into thinking they were exact for all cases. Will get back to you if/when I get a technically correct solution. 'Til then... I still believe there is a valid function, since the Square case is technically correct @ 1/(Abs[Sin(x)]+Abs[Cos[x]]) or 1/(Abs[Cos[x]]+[Abs[Cos[x-(Pi/2)]]]). Just need the technically correct coefficient... will work on it as I've got some time. But, for now, the incorrect versions are darned close! ;o) Enough to fool most people (including me, apparently).

-

Depends what you accept as "a general equation" and what is "a plot". For example, under the $l_1$ metric, the equation of what is perceived as a circle ( points having the same distance to a center) ends up looking like a square. Now would that count as genuine plot? Or, are we only allowed the Euclidean metric for plotting? Also, is an answer containing a limit acceptable? For example $$x^{2n}+y^{2n}=r^{2n} \lim_{n \to +\infty}$$ is a square ( or is it? ) see this for $n=18$

Also is the equation implicit in x and y or polar and parametric plots are also allowed?

-

How's this (Mathematica code)? It gives the n-gons inscribed in the unit circle, with vertices at the nth roots of unity.

Manipulate[PolarPlot[Cos[Pi/n] Sec[(2/n) ArcTan[Cot[(n t/2)]]], {t, 0, 2 Pi}], {n, 3, 40, 1}]

-
I finally got this to work: polarplot [ cos(Pi/7)/cos( | (t mod (2Pi/7)) - (2Pi/(2*7)) | ) , {t,0,2Pi}] Replace "7" with the number of sides you want. Read the explanations of how I got that equation here: polymathprogrammer.com/2014/01/29/… –  Vincent Tan Feb 18 at 11:12

Simply enough:

r(θ) = sec(θ%(π/n')-π/n)

When n' = n/2 and % is the modulus operator.

It would work just as well with cosecant as with secant.

Also the apothem would be 1 and the radius sec(-π/n).

-