<p>You can use the equation of a circle to do this. A circle can be drawn using the equation:</p>

<p>$r^2 = x^2 + y^2$</p>

<p>You can solve for the upper half of this by rewriting it in terms of $y$ like this:</p>

<p>$y^2 = r^2 - x^2$</p>

<p>so</p>

<p>$y = ±√(r^2 - x^2)$</p>

<p>But we only want the positive half. So we say just:</p>

<p>$y = √(r^2 - x^2)$</p>

<p>You can then repeat it by using (((x - 2) % 4) - 2) as the input value. In the end the equation is this:</p>

<p>$y = √(1^2 - (((x - 2) mod 4) - 2)^2)$</p>

<p>It looks like this:</p>

<p><a href="https://i.sstatic.net/A1OgD.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/A1OgD.png" alt="semicircles"></a></p>

<p>In graph toy, it would be:</p>

<pre><code>sqrt(1 - pow((((abs(x) - 2) % 4) - 2),2))
</code></pre>

CC BY-SA 3.0
2018-03-11T02:14:35.797Z
I think the OP wants arbitrary regular polygons though, like in the Desmos they linked, not just circles.
Nathan Reed
CC BY-SA 3.0
2018-03-12T07:01:08.823Z
Instead of using sqrt I think `max(sin(x),0)` is better
Seyed Morteza Kamali
CC BY-SA 3.0
2018-03-12T07:39:01.307Z
@NathanReed that's right I need regular polygons not just circles
Seyed Morteza Kamali
CC BY-SA 3.0
2018-03-09T03:23:31.073Z
2018-03-09T03:23:31.073Z
user1118321
<p>I drew simple <a href="https://en.wikipedia.org/wiki/Triangle_wave" rel="nofollow noreferrer">triangle wave</a> (that you can see It on <a href="http://www.iquilezles.org/apps/graphtoy/" rel="nofollow noreferrer">graph toy</a>).</p>
<p><img src="https://user-images.githubusercontent.com/16706911/37163629-80fb47c2-230d-11e8-9210-736648fb74a4.png" alt="triangle wave" /></p>
<pre><code>   f1(x) = frac(x/(PI+5))*(PI+5)
   f2(x) = frac(-x/(PI+5))*(PI+5)
   f3(x) = min(f1(x),f2(x))*1.5
</code></pre>
<hr />
<p>I want to change above shape like <a href="https://www.desmos.com/calculator/hmcutwfumj" rel="nofollow noreferrer">Approximating Pi</a> and repeat It periodically along the horizontal axis.</p>
<p><img src="https://user-images.githubusercontent.com/16706911/37164290-167419cc-230f-11e8-9e65-75aca83d33c5.gif" alt="Approximating Pi" /></p>
<p>then I want to cut negative parts of the vertical axis:</p>
<p><img src="https://user-images.githubusercontent.com/16706911/36645755-be8cd206-1a82-11e8-9046-dd2923095e16.png" alt="image" /></p>
<h1>Update</h1>
<p>Note that I know how can I draw It by shader In <a href="https://www.shadertoy.com/view/XsVyzR" rel="nofollow noreferrer">ShaderToy</a>.I Just need drawing mathematics In desmos or graphtoy,because I want Extract values of wave.I want to create polygon <a href="https://en.wikipedia.org/wiki/Waveform" rel="nofollow noreferrer">wave form</a>.</p>
<p>I drew Periodic shape that I want to change the number of polygons
<a href="https://www.desmos.com/calculator/gh7fmcrbys" rel="nofollow noreferrer">Desoms Link</a>.</p>

CC BY-SA 3.0
2018-03-13T13:54:40.200Z
I'm not familiar with graphtoy, but I think I can explain how to do this in terms of raw math - would that help?
Pikalek
CC BY-SA 3.0
2018-03-13T14:33:49.753Z
@Pikalek Anyway, I'd appreciate if you answer my question
Seyed Morteza Kamali
<mathematics>
How can I draw regular polygons along the horizontal axis?
Seyed Morteza Kamali
# How can I draw regular polygons along the horizontal axis?

(Asked by: username_0 on 2018-03-08)

I drew simple [triangle wave](https://en.wikipedia.org/wiki/Triangle_wave) (that you can see It on [graph toy](http://www.iquilezles.org/apps/graphtoy/)).

![triangle wave](https://user-images.githubusercontent.com/16706911/37163629-80fb47c2-230d-11e8-9210-736648fb74a4.png)

```
   f1(x) = frac(x/(PI+5))*(PI+5)
   f2(x) = frac(-x/(PI+5))*(PI+5)
   f3(x) = min(f1(x),f2(x))*1.5

```

---

I want to change above shape like [Approximating Pi](https://www.desmos.com/calculator/hmcutwfumj) and repeat It periodically along the horizontal axis.

![Approximating Pi](https://user-images.githubusercontent.com/16706911/37164290-167419cc-230f-11e8-9e65-75aca83d33c5.gif)

then I want to cut negative parts of the vertical axis:

![image](https://user-images.githubusercontent.com/16706911/36645755-be8cd206-1a82-11e8-9046-dd2923095e16.png)

# Update

Note that I know how can I draw It by shader In [ShaderToy](https://www.shadertoy.com/view/XsVyzR).I Just need drawing mathematics In desmos or graphtoy,because I want Extract values of wave.I want to create polygon [wave form](https://en.wikipedia.org/wiki/Waveform).

I drew Periodic shape that I want to change the number of polygons
[Desoms Link](https://www.desmos.com/calculator/gh7fmcrbys).

**Tags:** mathematics

> **Comments:**
> **username_1**: I'm not familiar with graphtoy, but I think I can explain how to do this in terms of raw math - would that help?  
> **username_0**: @username_1 Anyway, I'd appreciate if you answer my question  

---

## 1 answers

### Answer by username_2 on 2018-03-09. Score: 1

You can use the equation of a circle to do this. A circle can be drawn using the equation:

$r^2 = x^2 + y^2$

You can solve for the upper half of this by rewriting it in terms of $y$ like this:

$y^2 = r^2 - x^2$

so

$y = ±√(r^2 - x^2)$

But we only want the positive half. So we say just:

$y = √(r^2 - x^2)$

You can then repeat it by using (((x - 2) % 4) - 2) as the input value. In the end the equation is this:

$y = √(1^2 - (((x - 2) mod 4) - 2)^2)$

It looks like this:

[![semicircles](https://i.sstatic.net/A1OgD.png)](https://i.sstatic.net/A1OgD.png)

In graph toy, it would be:

```
sqrt(1 - pow((((abs(x) - 2) % 4) - 2),2))

```

> **Comments:**
> **username_3**: I think the OP wants arbitrary regular polygons though, like in the Desmos they linked, not just circles.  
> **username_0**: Instead of using sqrt I think `max(sin(x),0)` is better  
> **username_0**: @username_3 that's right I need regular polygons not just circles  

---

