Effacer les filtres
Effacer les filtres

Intersection of Discretized Curves

8 vues (au cours des 30 derniers jours)
Prasanna Routray
Prasanna Routray le 21 Juin 2024
Commenté : Star Strider le 21 Juin 2024
Hi,
I have a scatter plot of two curves.
The curves intersect each other and ideally they should have one or more intersection points.
However, as I have discrete points and two curves do not intersect at any of those points, I can not get the point of intersection.
I'm attaching a figure for more clarity.
I believe I will have a set of points here instead a single point.
How do I get those set of points from the scatter plot data or the data points I have now?
Thanks..
  2 commentaires
Tony
Tony le 21 Juin 2024
The pair of points on the two curves with the smallest Euclidean distance between them will be the intersection point. If you are looking for multiple, then you can put a threshold; e.g. find the pairs of points whose distance is less than 1e-6
Prasanna Routray
Prasanna Routray le 21 Juin 2024
Hi.. thanks for the reply. How do I do that?

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 21 Juin 2024
It would help to have the data.
TThe approach to these problems is straightforward. In this instance, the independent variable values are different, so the second curve needs to to be interpoalted to the values of the first independent variable (or the reverse of this, depending on what you want to do). After that, it is relatively straightforward to interpolate to find the intersection. (If there are more than one intersection, it will first be necessary to find all the approximate indices of the intersections, and then loop to find the exact values of each intersection.)
Try this —
x1 = linspace(0, 0.06);
y1 = -x1.^2;
x2 = linspace(0, 0.058);
y2 = 1E-3 - x2.^2 * 1.5;
figure
plot(x1, y1, '.')
hold on
plot(x2, y2, '.')
hold off
y2i = interp1(x2, y2, x1, 'pchip', 'extrap'); % Values Of 'y2' Interpolated To 'x1'
intxx = interp1(y1-y2i, x1, 0) % Y-Coordinate Of Intersection
intxx = 0.0447
intxy = interp1(x1, y1, intxx) % X-Coordinate Of Intersection
intxy = -0.0020
figure
plot(x1, y1, '.-')
hold on
plot(x1, y2i, '.-')
plot(intxx, intxy, 'cs')
hold off
text(intxx, intxy, sprintf('$Intersection\\ at\\ (%.4f, %.4f) \\rightarrow$',intxx,intxy), 'Horiz','right', 'Interpreter','LaTeX')
This should work with your data, as written. I will of course help with any problems if necessary in adapting this to your data.
.
  3 commentaires
Prasanna Routray
Prasanna Routray le 21 Juin 2024
I was also wondering about another way this could be tackled.
How about finding a set of points instead of a single exact point.
I'm not very sure about the method but what if the points represent a 2D normal distribution kind of representation? Just curious about that.
Star Strider
Star Strider le 21 Juin 2024
As always, my pleasure!
I am not certain what you intend by ‘set of points’. Since my code detects and plots the exact intersection, one option for ‘set of points’ could be to consider all the points within a specific Euclidian distance of the intersection, perhaps with the knnsearch function.
Consider something like this (untested):
edist = 1E-3; % Distance Threshold (Limit)
[C1_idx,D1] = knnsearch((x1-intxx), (y1-intxy));
[C2_idx,D2] = knnsearch((x2-intxx), (y2-intxy));
Then, compare ‘D1’ and ‘D2’ separately with ‘edist’ to return a logical vector that can then be used with the index vectors to return the points referenced to them.
.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by