I drew simple triangle wave (that you can see It on graph toy).

triangle wave

   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 and repeat It periodically along the horizontal axis.

Approximating Pi

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



Note that I know how can I draw It by shader In ShaderToy.I Just need drawing mathematics In desmos or graphtoy,because I want Extract values of wave.I want to create polygon wave form.

I drew Periodic shape that I want to change the number of polygons Desoms Link.

  • $\begingroup$ I'm not familiar with graphtoy, but I think I can explain how to do this in terms of raw math - would that help? $\endgroup$ – Pikalek Mar 13 '18 at 13:54
  • $\begingroup$ @Pikalek Anyway, I'd appreciate if you answer my question $\endgroup$ – Seyed Morteza Kamali Mar 13 '18 at 14:33

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$


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


In graph toy, it would be:

sqrt(1 - pow((((abs(x) - 2) % 4) - 2),2))
  • $\begingroup$ I think the OP wants arbitrary regular polygons though, like in the Desmos they linked, not just circles. $\endgroup$ – Nathan Reed Mar 11 '18 at 2:14
  • $\begingroup$ Instead of using sqrt I think max(sin(x),0) is better $\endgroup$ – Seyed Morteza Kamali Mar 12 '18 at 7:01
  • $\begingroup$ @NathanReed that's right I need regular polygons not just circles $\endgroup$ – Seyed Morteza Kamali Mar 12 '18 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.