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 almostsquare:
PolarPlot(0.75 + ArcSin(Sin(2x+Pi/2))/(Sin(2x+Pi/2)*(Pi/4))) (x from 0 to 2Pi)
This input gave an almostoctagon:
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 nonexistence be proven? If there are equations, but only for certain polygons (for example, only for n<7 or something), can those equations be provided?
Answer
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)∈R2,f(x,y)=0}.

If C1 and C2 are given by f1 and f2 respectively, then C1∪C2 is given by f1.f2 and C1∩C2 is given by f21+f22 (or f1+f2). So if C1 and C2 can be described by an equation involving absolute values and polynomials, then so do C1∪C2 and C1∩C2.

If C={(x,y)∈R2,f(x,y)≥0}, then C is given by the equation f−f.
Now, any segment S can be described as S={(x,y)∈R2,ax+by=c,x0≤x≤x1,y0≤y≤y1}, 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(π/8), c=cos(π/8), then one segment is given by y≤rs and x=rc, for which an equation is
f(x,y)=rs−y−(rs−y)+x−rc=0
So I think the octagon is given by
f(x,y) f(y,x) f(x+y√2,x−y√2)=0
To get a general formula for a regular polygon of radius r with n sides, denote cn=cos(π/n), sn=sin(π/n) and
fn(x+iy)=rsn−y−(rsn−y)+x−rcn
then your polygon is given by
n−1∏k=0fn(e−2ikπn(x+iy))=0
Depending on n, you can use symmetries to lower the degree a bit (as was done with n=8).
Attribution
Source : Link , Question Author : Vincent Tan , Answer Author : Joel Cohen