[Math] Polygon sine waves

functionsgeometrypolygonstrigonometry

So I came across this picture on Google+ and I wanted to understand further. I created an equation for the second wave, the one with the square. Here it is:
$$y=\frac{\sin x}{\cos(\min(x \mod \pi/2, \pi/2- (x \mod \pi/2)))}$$

(The equation plotted on Wolfram Alpha.)

It's fine, but I feel like using mod and min is kind of nasty. Can anyone offer improvement to my equation and/or general insight towards further polygons?

Best Answer

Start with a "triangle" function of period $2 \pi/n$, minimum value $0$ and maximum value $\pi/n$: a suitable choice is $T_n(t) = \frac{1}{n} \arccos(\cos(n t))$. A regular $n$-gon of inradius $r_0$ is given, in polar coordinates, by $r = r_0/\cos(T_n(\theta - \theta_0))$. Its $y$ coordinate is then $$y = \dfrac{r_0 \sin(\theta)}{\cos(T_n(\theta - \theta_0))}$$

Here is a similar animation using a pentagon ($n=5$):

enter image description here