Find the point between indices where two curves with unknown equations intersect

3 views (last 30 days)
Hi,
I have two curves that intersect when plotted on the same graph. I would like to find the point at which they intersect. I do not have the equations to describe the curves as they are just two sets of x- and y-coordinates, and the point of intersection falls somewhere between two indices.
(The real problem that I tried to simplify for myself as I'm a programming novice: I actually have one set of x- and y-coordinates that form a curve that intersects with itself. Again, I do not know the equation for this curve and the intersection point falls between two indices. I looked at some of the answers that were previous posted in response to a similar question, but the solution was more complicated than I was able to understand.)
I would appreciate any sort of direction, please, keeping in mind that I've just been newly introduced to Matlab! Thanks so much!
Jessica

Answers (1)

John D'Errico
John D'Errico on 27 May 2014
As long as you are willing to find the intersections of the piecewise-linear curves that interpolate your points using connect-the-dots, then look on the file exchange. For example, Doug's intersections code is very nice.
Your question is not very clear, so I'm not sure if you are looking for the intersections of separate curves, or for the intersection points of a self intersecting curve. In any event, Doug's code handles either case.
  2 Comments
Jessica
Jessica on 27 May 2014
Hi, John,
The original data produced one curve that intersects itself; however, I could not figure out how to find that point so I broke my data into two parts thinking this would be easier for me to figure out. I see now that this might seem silly to someone who knows what they're doing.
I had already looked at Doug's code in the link you provided above but still could not figure out how to apply it to my own data. I just have the x- and y-coordinates and do not have the equation to the curve as he does in his example. All I have is a joint angle over time that is in the first column of a matrix that is plotted against a different joint angle over time in the second column of the matrix. When they are plotted against each other and they intersect as it is a cyclical task.
I'm in the health care field so potentially out of my league when it comes to interpreting the majority of previously posted solutions.
Thanks for your prompt response.
Jessica
Matt J
Matt J on 28 May 2014
Edited: Matt J on 28 May 2014
I just have the x- and y-coordinates and do not have the equation to the curve as he does in his example.
I don't see anything in Doug's code that requires you to supply an equation for the curve or deviates from your situation in any way. The input syntax in his help documentation asks only for lists of (x,y) pairs, exactly what you say you have:
[X0,Y0] = intersections(X1,Y1,X2,Y2,ROBUST);
He also supports a syntax for the original situation you describe, where you want to find the self-intersections of a single curve.
[X0,Y0] = intersections(X1,Y1,ROBUST);
The code always assumes that the continuous "equation" for the curve is that all the (x,y) points are to be connected with line segments. So, you have to decide if you are happy with that approximation (if not, you need to decide what the alternative should be). Presumably, the code also assumes that your list of (x,y) data is ordered so that adjacent points on a curve are also adjacent in the list.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!