Function for concatenated semicircles

This works (for circles of radius $r$):

$$f(x)=(-1)^{\displaystyle\left\lfloor \frac{x}{2r}+\frac{1}{2}\right\rfloor}\sqrt{r^2-\left(x-2r\left\lfloor\frac{x}{2r}+\frac{1}{2}\right\rfloor\right)^2}$$

Image for $r=1$:

enter image description here

Mathematica code:

r = 1; Plot[(-1)^Floor[x/(2r) + 0.5] Sqrt[r^2 - (x - (2r)Floor[x/(2r) + 0.5])^2],
{x, -3, 3}, AspectRatio -> 1/3]

I have come up with an equation, which can be found at this desmos calculator I made. I derived this equation from $\arcsin(\sin(x))$ giving a zig-zag, and $\sqrt{-x^2+1}$ giving semicircles, then multiplied by the sign of cosine wave to invert every other semicircle. $n$ is the horizontal shift, $r$ is the radius.

the full form of the equation is as follows, with $n$ being the horizontal shift, and $r$ being the radius: $$f\left(x\right)=r\sqrt{-\left(\frac{2\arcsin\left(\sin\left(\frac{\pi x}{2r}+n\pi\right)\right)}{\pi}\right)^{2}+1}\cdot\operatorname{sign}\left(\cos\left(\frac{\pi x}{2r}+n\pi\right)\right)$$

Tags:

Functions