Different Types of Waves

309 Views Asked by At

I am making a basic 2D rigid body simulator as a hobby. It involves springs. Naturally, I need to render them. Rigid body simulators, such as Algodoo, render them simply like this
enter image description here

Another (more common) helical representation enter image description here

And many more...

So, to render these, I need some periodic function (with amplitude of $A$) which takes the number of turns $t$ (The number of turns is the same as the number of periods in the wave. E.g $\sin(x)$ contains $1$ turn in $[0,2\pi]$), and has the starting and end point $(x_1,y_1)$ and $(x_2,y_2)$ respectively. The end point and the starting point must be at "mean" position of the amplitude. (E.g $f(x)=0$ in $f(x)=\sin(x)$)
Any helical or triangle-wave like (or perhaps some other representation?) function will do. I don't know how to approach this.
I don't have access to built in functions for triangle waves, et cetera. Any suggestions?
Thank you.

3

There are 3 best solutions below

1
On BEST ANSWER

The basic problem is to obtain the parametric representation of the projected spring $\gamma$ in your second figure, connecting the points $(0,0)$ and $(1,0)$. Apart from the $y$-amplitude $A>0$ we can choose the number $2n+1$ of half-waves and a parameter $B>0$ which encapsulates the degree of selfintersection of $\gamma$. As a function of time, $\gamma$ is a superposition of a clockwise elliptical motion $$t\mapsto\bigl(x_e(t),y_e(t)\bigr):=(A\sin t,-B\cos t)\qquad\bigl(0\leq t\leq(2n+1)\pi\bigr)$$ and a linear motion in $x$-direction, described by $$t\mapsto x(t):=a+ bt\ ,$$ where $a$ and $b$ have to be chosen suitably. Therefore the parametric representation of $\gamma$ looks as follows: $$\gamma:\quad t\mapsto\left\{\eqalign{x(t)&:=a+bt-B\cos t \cr y(t)&:=A\sin t\cr}\right.\qquad\bigl(0\leq t\leq (2n+1)\pi\bigr)\ .\tag{1}$$ The condition $x(0)=0$ gives $a=-B$, and $$1=x\bigl((2n+1)\pi\bigr)=2B+(2n+1)\pi b$$ leads to $$b={1-2B\over (2n+1)\pi}\ .$$ In this way the representation $(1)$ becomes $$\gamma:\quad t\mapsto\left\{\eqalign{x(t)&:=B(1-\cos t)+{1-2B\over (2n+1)\pi}\>t\cr y(t)&:=A\sin t\cr}\right.\qquad\bigl(0\leq t\leq (2n+1)\pi\bigr)\ .$$ The reasonable condition $x(2\pi)>0$ implies $0<B<{1\over2}$. The following figure shows the resulting $\gamma$ when $n=6$, $A=0.2$, and $\>B=0.11$: enter image description here

Now we have to transform $\gamma$ into a spring with given endpoints $(x_0,y_0)$, $\>(x_1,y_1)$. Let $$d:=\sqrt{(x_1-x_0)^2+(y_1-y_0)^2},\qquad\phi:=\arg(x_1-x_0,y_1-y_0)\ .$$ Then the coordinates of the transformed point $(\bar x,\bar y)$ are obtained from $(x,y)$ by the operation $$\left[\matrix{\bar x\cr \bar y\cr}\right]=\left[\matrix{x_0\cr y_0\cr}\right]+d\ \left[\matrix{\cos\phi&-\sin\phi \cr \sin\phi&\cos\phi\cr}\right]\>\left[\matrix{x\cr y\cr}\right]\ .$$

9
On

$$\boxed{\huge\arcsin(\sin x)}$$ enter image description here

Specific Purpose Equation:

$$(y-y_1)=2\frac A{\pi}\arcsin\left(\sin \left(t\frac {(x-x_1)}{2\pi}\right)\right)$$

4
On

In parametric form, you could get your spring's shape as a function of $t$ turns and amplitude $A$, about an interval of the $x$-axis:

$$f_{x}(A,t)=A(2t\pi-2\cos(2t\pi))\\ f_{y}(A,t)=A\sin(2t\pi).$$

It would be quite simple to take this curve on an interval of desired length, rotate it, and then map it to the desired line in the plane. Also, if you want the crests to be more spread out or squashed together, just augment the $x$ component accordingly.