How can I change gap length between the hills?

187 Views Asked by At

I drew hills by using max(sin(x),0) that you can see this on desmos.

hill

I need to change distance between hills without changing size.

image

2

There are 2 best solutions below

2
On BEST ANSWER

Here is a short solution for any gap $g$.

In desmos enter the following: hills with arbitrary gaps

Move the $g$-slider to see the gaps changing size.

Here you see, how it is built:

enter image description here

7
On

Enter the floor function. Using this, we can make the function $x$ "skip forward" at even intervals, thus shortening the gaps exactly the way we want. So, we are going to use the setup $\max(0, \sin(h_1(x)))$, where $h_1(x) = x + c\lfloor h_2(x)\rfloor$ for some $h_2(x) = ax + b$ that we will have to construct and some constant $c$.

So, in order to figure out what we want from $h_2(x)$, we need to figure out what we want from $h_1$. We want some fixed period $\pi + k$ such that in one period $h_1(x)$ increases by exactly $2\pi$. We want $h_1(x)$ to have slope $1$ for the most part (this is achieved by the $x$ term), and then have a jump discontinuity once per period, which is achieved by $a\lfloor h_2(x)\rfloor$.

How large is this jump discontinuity (controlled by $c$), and how often ant at what points will they happen (controlled by $a$ and $b$)? Well, one period is $\pi +k$, and we want the graph to increase by $2\pi$ in this time, so the remaining $\pi - k$ change in function value will have to be done by the discontinuity jumps. The jumps of the floor function are $1$, so that means that $c = \pi - k$.

The frequency of the gaps (controlled by $a$) next: The period is $\pi + k$, and for each period we need exactly one skip. That means that $h_2(x)$ has to increase in value by exactly $1$ each period. So $a = \frac1{\pi + k}$.

Finally, the position of the jump, controlled by $b$. We can basically put this wherever we want in the gap, but I'll place it at the end of the gap, because that's easiest. One end of a gap happens right at $x = 0$, so we want $h_2(0)$ to be an integer, which makes $b = 0$ a really simple choice.

So that's it. We now have the function $$ \max(0, \sin(h_1(x))) = \max\left(0,\sin\left( x +(\pi - k)\lfloor h_2(x)\rfloor\right)\right)\\ = \max\left(0,\sin\left( x +(\pi - k)\left\lfloor \frac{x}{\pi + k}\right\rfloor\right)\right) $$ and a Desmos link here (I don't know for how long that link will keep working, though).

Fair warning: This really cannot cope with a gap larger than $\pi$. If you plot $\sin(h_1(x))$ as well, or just extend the range of $k$, you can see what happens. If we instead put the jump in the middle of the gap (which requires some more working-out of $b$, since instead of $h_2(0)$ to be an integer, you want $h_2(-k/2)$ to be an integer), then this can handle a gap of up to $2\pi$.