# detect when a line crosses a curve more than 2 times

I have a set of plotted X,Y data points making a curve as shown below in the black line. What i need to do is draw a line from each of the X,Y s to all of the other XYs to determine the one with the highest slope for each point.

any line that intersects the curve more that 2 times IE the green line below are invalid. Can you think of a way to find all the common points of the Line and the curve given that i have all the XY to define the curve and all the XY at either end of the lines

here are some sample datapoints

POINT   x       y       Slope
1       0.00    1.00    #DIV/0!
2       0.79    -1.00   -2.55
3       1.57    -4.00   -3.18
4       2.00    -7.00   -4.00
5       2.36    -2.00   -1.27
6       2.55    8.00    2.75
7       3.14    12.00   3.50
8       3.93    -0.71   -0.43
9       4.71    0.00    -0.21
10      5.50    0.71    -0.05
11      6.28    1.00    0.00
12      7.07    0.71    -0.04


grid

graph

this is a beter picture illustrating the slopes being all over the place so i am not sure if finding m+1 being a lesser value will work

Ok FleaBlood I am not understanding Ill include another graph and table to clarify

• Do you have a definition for the curve? Otherwise there exist lots of curves passing through those points. Commented Jul 28, 2017 at 15:45
• To me this question is indeed about mathemathics but if you mainly concern about the implementation you can go to stackoverflow for example. Commented Jul 28, 2017 at 15:49
• Are the x distinct (i.e. is this a function)? If not how do you determine which curve connects the dots? Is the final goal to only keep the point with the highest slopes with a point? If so you don't need to worry about crossing lines and a those slopes will not be the highest slope. Commented Jul 28, 2017 at 15:52
• hey dude I looked there couldnt find an example? stackoverflow Commented Jul 28, 2017 at 16:50

So measure slopes $m_1, m_2, m_3, m_4$. If you ever get a slope where $m_{i+1} \le m_i$ then $m_{i+1}$ and all the previous slopes, $m_j$, so that $m_{i+1} \le m_j \le m_i$ pass through the curve twice.