How to determine the exact intersection between line and two curves
Show older comments
Data is attached.
Hi everyone,
I am trying to find the exact intersection between line and curve and I tried everything and all they gave me an approximate intersection. Can anyone help me to determine the exact intersection. Thanks in advance,
I used " intersect points=find(p1==p2)"
intersectionpoints =
0×1 empty double column vector
However, If i used intersectionpoints=find(p1>=p2)
intersectionpoints =
9 10 11 12 13 14 18 19 20 21 22
So 9 is not the exact point, it is the point after the intersection between p1 and p2, how to find the exact intersected point between the red line and the blue curve.

Accepted Answer
More Answers (1)
Torsten
on 14 Mar 2022
Depending on how you interpolate between the points of the blue curve, you will get different intersection points.
So there is no "exact" intersection you can expect to get.
If (x,y) are the points of the blue curve and y0 is the y-value of the orange curve, you can do something like:
i = 0;
for j = 1:numel(x)-1
xl = x(j);
yl = y(j);
xn = x(j+1);
yn = y(j+1);
if yl <= y0 & yn >= y0
i = i+1;
xi(i) = (y0*(xn-xl)+xl*yn-xn*yl)/(yn-yl);
end
end
xi
This will give you an approximation for the x-coordinates of the intersection points.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!