# Drawing a fitted wave sine between any two points in 2d

I'm trying to draw a sine wave with specified start point, end point and length. To do so I have already done finding Amplitude and Period for sine function.

The problem is that sine wave is not fitted into points (its below). Please take a look: What I thought how to solve this: 1) Create two vectors. First vector is from starting to ending point and second vector is from starting wave point to ending wave point 2) Calculate angle between them 3) Try to rotate the sine wave with computed angle 4) Add y offset in order to fit sine wave between points (see output image)

But...There is a problem, the sine is not rotated in desired angle as You can see in this image (the blurred waves are made in graphic app). What is the problem?

Data:

objectStart = {-0.6061,0.2351}
objectEnd = {-0.1999,0.1787}
found sine = {y= 0.1 * sin( 24.85 * x)+0 foundLen=0.78}
curveStart = {-0.6061,-0.0601}
curveEnd = {-0.1999,0.0967} v1 = {0.4061,-0.0563}
v2 = {0.4061,0.1569}
angleBetweenVectors = 29.027 angleBetweenLineAndCurvePoints = -90.0

Code with comments: http://pastebin.com/gxTftAB9

Thanks for any help! Regards!

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

I have found that angle between vector divided by 2 (which is about 15 degree) is mine desired angle. But why I have to divide it by 2? Anyone knows?

## 1 Answer

Ok, I have found how to fit my sine curve. I have done it by adding delta y between those two vectors into the value of found sine function (blue). However, the sine wave which is now fitted between points is a little bit different (violet). I got a question for all you experts, does it affect the length of sine wave which i found or the length of the original and "moved" curves are the same? Here is the image 