How to generate a sine curve between two points

11.9k Views Asked by At

Pic.1 Sine curve example

Shown from Pic.1 is a example sine curve about my question. The precondition is there are two points, such as P1(x1, y1), P2(x2, y2), and I want to generate a sine curve between these two points.

The general equation of a sine curve is y = Asin(wx + φ) + b, there is no problem to get the w, φ and b from those two points, but I have no idea how to get the amplitude of the sine curve just shown in Pic.1. Is there anyone who is familiar with this? please give me some clue. Thank you.

PS:The curve shown in Pic.1 may not be a sine curve, but I just can't figure out other curves with this shape. So if you think it's not a sine curve, please give me you equation of this curve.

--------UPDATE---------

There is an additional constraint, please see Pic.2, the generated sine curve should not go over the two black lines whether the distance between the two given points is long or short, and the black lines should be the tangent line of the sine curve. Is this constraint helpful to get the amplitude?

Pic.2 additional constraint

4

There are 4 best solutions below

2
On BEST ANSWER

We are looking for an amplitude $A$ of an initial function (see graphic below) that can be described in a parametrical manner:

$$\cases{x(t)=t\\y(t)=A \sin(2 \pi t)} \ \ \ \ \text{for} \ \ 0 \leq t \leq 1$$

We desire to obtain parametric equations for the transformed curve, knowing that this curve results from the initial curve by the successive actions of:

  • an enlargement (with ratio$K$),

  • a rotation with angle $\theta$,

  • and, finally, a translation bringing origin $(0,0)$ (thus for $t=0$) onto point $(x_1,y_1).$

Using matrix notations, the transformed curve is parametrically described by:

$$\tag{1}\pmatrix{X(t)\\Y(t)}=K \pmatrix{\cos(\theta)&-\sin(\theta)\\\sin(\theta)&\ \ \cos(\theta)}\pmatrix{t\\A\sin(2 \pi t)}+\pmatrix{x_1\\y_1}$$

or explicitly

$$\tag{2} \cases{X(t)=K(\cos(\theta)t-\sin(\theta)\sin(2\pi t))+x_1\\Y(t)=K(\sin(\theta)t+A\cos(\theta)\sin(2\pi t))+y_1}$$

We need to find the values of 3 parameters, $\theta$, $K$ and $A$.

  • Let $S=\frac{y_2-y_1}{x_2-x_1}$ denote the slope. Rotation angle $\theta$ is such that $tan(\theta)=S$. Thus:

$$\theta=atan(S)$$

  • $K$ is determined by the fact that, for $t=1$, we must be "arrived at" $(x_2,y_2)$. Plugging $t=1$, and thus $X(1)=x_2$ into the first equation of (2) gives $$K=\dfrac{x_2-x_1}{\cos(\theta)}.$$

  • Now, for amplitude $A$, it suffices to impose the horizontal tangent constraint

$$dY(t)/dt|_{t=0}=0 \ \ \iff \ \ \sin(\theta)+2\pi A\cos(\theta)\cos(2\pi t)=0 \ \ \text{for} \ \ t=0, \ \ $$

yielding:

$$A=-\dfrac{\tan(\theta)}{2 \pi}=-\dfrac{S}{2 \pi}$$


Here is a Matlab program implementing (2):

clear all;close all;hold on;

x1=1;y1=3;x2=5;y2=1;

slo=(y2-y1)/(x2-x1);

th=atan(slo);

c=cos(th);s=sin(th);

A=-slo/(2*pi);K=(x2-x1)/c;

t=0:0.01:1;

plot(K * (c * t - s * sin(2*pi*t)) + x1, K *( s * t + A * sin(2*pi*t)) + y1);

plot([x1,x2],[y1,y2]);

enter image description here

3
On

You are short one constraint. The distance between the points sets $w$ as you seem to want one full cycle between the points. $\phi=0$ if you measure $x$ from one end and want the curve to go through the points because you want to start with the argument of $\sin$ equal to zero. You don't have anything to set the amplitude. In you picture, it seems the amplitude could be anything.

Your update will place a maximum on $A$. If you want to leave the starting point horizontally, it will specify it. You want the slope of your sine wave (viewed as if the baseline were horizontal) to be the negative slope of the line between the points. If the slope of the line is $-m$ (as you have drawn it negative), the derivative of your function is $f'(x)=Aw\cos(wx+\phi)$ At the start, we said $x=\phi=0$, so you want $Aw=m$

1
On

HINT:

Let ${ P_1P_2} $ cut $ x-$ axis at $O$ at an angle $\gamma$ to $x-$ axis

Inclination of ${ P_1P_2}$ is $ m = \dfrac{(y_2-y_1)}{(x_2-x_1)} $

Amplitude $ A = \dfrac {m \overline{\,P_1P_2} }{2\pi }$

Rotate by angle $ -\gamma$ . The rotated equation has form $$ y= A \sin { 2 \pi ( x+ OP_1 \cos \gamma) \over {\,P_1P_2} } $$

Rotate back to original position.

Can you see how it is so, and take it further?

2
On

It seems to from the second diagram that what you want is a Bezier curve, rather than a sine curve. The Bezier curve is best suited for this because the parameters define the end point as well as the angle at which the curve leaves or enters the end points. Pl. take a look into them.