2
$\begingroup$

The goal is to create an animation curve mathematically that moves like a sin curve but holds at the extremes. I would also love to be able to parameterize it.

Image showing desired graph behavior In the graph note how the domain spent at either 1 or -1 increases while the function still transitions smoothly in and out of these extremes.

Thus far I have graphs of the following forms with no luck

sin(x)*sin(x)^a
sin(x)^a // This sort of works when a is [0, 1] however I do not like that the derivative appears infinite when y =0
sin(sin(x))
sin(x)+sin(x+a)

I really have not seen a formula that can do this. Is it even possible to translate a regular sine curve into one that lingers at its extremes?

A function that is not even technically sinusoidal would be ok so long as it is periodic or can be made periodic by modulo-ing x.

$\endgroup$
2
  • 4
    $\begingroup$ Does this answer your question? 'Cosine'-esque function with flat peaks and valleys. The derivative is very steep around $x = \frac{\pi}{2}, \frac{3 \pi}{2} \cdots$ but is not actually infinite: this is a natural consequence of flattening the curve. $\endgroup$
    – Toby Mak
    Commented Feb 6, 2021 at 0:25
  • $\begingroup$ A square wave is the limit of a certain infinite sum of sine waves (its Fourier series), see en.wikipedia.org/wiki/Square_wave. However, sine waves are slow to compute and the partial sums of the square wave series have undesirable overshoots near the vertical part. So usually a polynomial approximation is preferable, like $1-x^{2n}$ from about -1 to 1 and $(x-a)^{2n}$ (with $a$ chosen so they line up) from about 1 to 3, and repeat it. desmos.com/calculator/ehyhl6lphd $\endgroup$
    – hacatu
    Commented Feb 6, 2021 at 0:30

1 Answer 1

2
$\begingroup$

Try:

$$f(x) = \frac{\vert\sin x\vert^{2-p}}{\sin x}$$

If $p=0$, you have a regular sine curve: enter image description here When $p$ goes from $0$ to $1$, the function smoothly goes between the extremes. $p = \frac{1}{2}$: enter image description here Finally, as $p$ goes to $1$ you get the square wave. enter image description here The function can also be written as:

$$f(x) = \text{sgn}(\sin x)\cdot\vert\sin x\vert^{1-p}$$

This might give some more intuition as to why it works. For more, see Desmos.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged .