-1

I have been trying to create a curve and i've already created it . but the thing is if i add a point it will be added to the array[last point -1] , but if i add a point between the first and second point the curve takes it as the last point -1 which is my coding anyway, I need to find where i shoulkd add , the index of the curveenter image description here

The above imnage is an example , here i have a curve with three points , the point's are numbered so that you can see how the points are stored in the array , I am going to add the purple point to th array but i need to know which index i should paste , please help

Jeffin
  • 1,099
  • 12
  • 23

3 Answers3

0

1- Any curve you create will be having some equation . eg X^2 + Y -3 = 0

2- if your point is in that curve it should satisfy this equation.

0

For every point lying on Bezier curve, you can find parameter t in range 0..1. So insert new point in the list according to it's t-value.

About t finding:

-if you curve is monotone along X coordinate (similar for Y), just solve cubic equation for t:

P0.X*(1-t)^3 + 3*P1.X*t*(1-t)^2 +3*P2.X*t^2*(1-t) +P3.X*t^3 = NewPoint.X

-if not, you can solve similar equation both for X and for Y and get consistent solution (self-intersecting curve may have two solutions)

-for inexact coordinates you can build expression for squared euclidean distance from point to curve and find it's minimum (closest point)

MBo
  • 77,366
  • 5
  • 53
  • 86
0

I just created new seperate sprites for each of the curves and found the points when the click event is dispatched , thanks for your suggestions.

Jeffin
  • 1,099
  • 12
  • 23