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?

  • 1
    $\begingroup$ 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. $\endgroup$ Commented May 29, 2011 at 11:48
  • 1
    $\begingroup$ The answer depends on what kind of functions you're allowing in such an equation. $\endgroup$ Commented May 29, 2011 at 12:08
  • $\begingroup$ If you can use rotation matrices then I would assume its possible... $\endgroup$
    – soandos
    Commented May 29, 2011 at 12:17
  • $\begingroup$ Qiaochu, any function can be used. As long as the resulting polygon is continuous (no breaks) and defined using that one equation. $\endgroup$ Commented May 29, 2011 at 15:13

12 Answers 12


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$).

  • $\begingroup$ Hi Joel, can this result be used to generate some equations for regular polygons? tx $\endgroup$
    – jimjim
    Commented May 29, 2011 at 12:40
  • 3
    $\begingroup$ @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. $\endgroup$
    – Joel Cohen
    Commented May 29, 2011 at 12:54
  • $\begingroup$ 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. $\endgroup$ Commented May 29, 2011 at 15:11
  • 2
    $\begingroup$ @ Vincent : I added a general formula for any $n$ in the answer (not sure if that is what you're looking for). $\endgroup$
    – Joel Cohen
    Commented May 29, 2011 at 16:06
  • $\begingroup$ For an algorithm for getting a boolean formula for a polygon, see An efficient algorithm for finding the CSG representation of a simple polygon. $\endgroup$
    – lhf
    Commented May 29, 2011 at 20:06

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

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 contains 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.

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

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:

  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]]

regular polygons, 3-11

  • $\begingroup$ Do you have a citation for equation? (How you got in this equation?) $\endgroup$ Commented May 22, 2016 at 17:49
  • $\begingroup$ No citation, @Wagner; I derived it myself. I believe I already explained how I obtained it. $\endgroup$ Commented May 22, 2016 at 17:52
  • 1
    $\begingroup$ I am writing a dissertation and your equation help me so much, but not is my. Can I use it? $\endgroup$ Commented May 22, 2016 at 18:06
  • 3
    $\begingroup$ Sure, as long as you give attribution of course (per SE rules). :) $\endgroup$ Commented May 22, 2016 at 18:38
  • $\begingroup$ BTW, if it was truly helpful, I'd appreciate seeing the dissertation myself. $\endgroup$ Commented Jul 30, 2016 at 12:57

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$$

  • $\begingroup$ 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. $\endgroup$ Commented May 29, 2011 at 15:21

A more general formula exists, for star polygon too and its smoother variations:

$$1=\frac{\sqrt{x^2+y^2} \cos \left(\frac{2 \sin ^{-1}\left(k \cos \left(n \tan ^{-1}(x,y)\right)\right)+\pi m}{2 n}\right)}{\cos \left(\frac{2 \sin ^{-1}(k)+\pi m}{2 n}\right)}$$

or, with polar coordinates:

$$\rho = \frac{\cos \left(\frac{2 \sin ^{-1}(k)+\pi m}{2 n}\right)}{\cos \left(\frac{2 \sin ^{-1}(k \cos (n \phi ))+\pi m}{2 n}\right)}$$


$\phi$ - angle;
$\rho$ - radius;
$n$ - number of convex vertices;
$m$ - determines how many vertices the sides will lie on one straight line;
$k$ - hardness - for $k=0$ we get a circle regardless of other parameters, for $k=1$ - a polygon with straight lines, with intermediate values from $0$ to $1$ - intermediate figures between the circle and the polygon.

For more details see this paper (at russian)

sample image sample image


$\arcsin \left(\sin \left(\left[\sin \left(60\cdot \frac{\pi }{180}\right)\left(\frac{\sqrt{3}}{3}\cdot x+y\right),x\right]\right)\right)+\left(\frac{1}{3}\right)\cdot \arcsin \left(\sin \left(\left[\cos \left(30\cdot \frac{\pi }{180}\right)\left(x-\frac{\sqrt{3}}{3}y\right),y\right]\cdot \sqrt{3}\right)\right)=0$


I came up with this to plot a hexagon tessellation in desmos....the [list] funct "hides" the overlay ...so it isn't really a single EQ.....actually there was very little info on this.....took me weeks....enjoy

  • $\begingroup$ Very clever! (+1) $\endgroup$ Commented Jan 10, 2019 at 18:03

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).

  • $\begingroup$ What is the difference between this and Raskolnikov's answer? $\endgroup$ Commented Aug 17, 2015 at 7:53

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:

(n-gon, circumradius=1, unrotated)

(n-gon, circumradius=1, rotated $-\pi/4$)

(n-gon, function centered around unit circle, unrotated)

(n-gon, function centered around unit circle, rotated $-\pi/4$)

(n-gon, apothem=1, unrotated)

(n-gon, apothem=1, rotated $-\pi/4$)

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


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... ;)

~Michael Gmirkin


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}]

  • $\begingroup$ 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/… $\endgroup$ Commented Feb 18, 2014 at 11:12
  • $\begingroup$ You're basically using $\arctan \cot x$ here as your sawtooth… :) $\endgroup$ Commented Aug 17, 2015 at 7:54

A cheap trick: Take an equation that represents the union of the extensions of the polygon’s sides and add a domain-limiting term to both sides.

For example, the equation $$(x-C)(x+y-\sqrt2C)(y-C)(x-y+\sqrt2C)(x+C)(x+y+\sqrt2C)(y+C)(x-y-\sqrt2C)+\sqrt{1-x^2-y^2}=\sqrt{1-x^2-y^2}$$ with $C=\cos{\frac\pi8}$ describes a regular octagon. For a regular polygon with an even number of sides, you can pair up opposite sides to halve the number of terms: $$(x^2-C^2)((x+y)^2-2C^2)(y^2-C^2)(x-y+\sqrt2C)((x-y)^2-2C^2)+\sqrt{1-x^2-y^2}=\sqrt{1-x^2-y^2}.$$

This obviously generalizes to polygons that are affine images of cyclic polygons, i.e., one whose vertices all lie on an ellipse.


In the context of this question you may define for a given number $n$ some (Fourier) coefficients by these sensible equations (as you have asked for):

$a^{(n)}_k \sim \begin{cases} +k^{-2} & \text{ for } k \equiv 1 \pmod n\\ +k^{-2} & \text{ for } k \equiv (n-1) \pmod n\\ 0 & \text{ otherwise } \end{cases}$

$b^{(n)}_k \sim \begin{cases} +k^{-2} & \text{ for } k \equiv 1 \pmod n\\ -k^{-2} & \text{ for } k \equiv (n-1) \pmod n\\ 0 & \text{ otherwise } \end{cases}$

Then you calculate the functions $a^{(n)}(t)$ and $b^{(n)}(t)$ like this:

$a^{(n)}(t) \sim \sum_{k=0}^\infty a^{(n)}_k\cos(kt)$

$b^{(n)}(t) \sim \sum_{k=0}^\infty b^{(n)}_k\sin(kt)$

Finally you draw the curve $t \mapsto a^{(n)}(t) + ib^{(n)}(t)$ in the complex plane – and get your desired regular $n$-gon.

As an example for $n=4$:

enter image description here

See more examples in the gallery here.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .