How to find which are the nearest points to the line segment?

12 次查看(过去 30 天)
I have a vector X size 50x1 and a vector Y size 50x1. If i
plot(X, Y, 'r+')
then I get the rays you can see at the plot (there are 50 but here you see only from ray 20 until aprox.46).
I also have a line segment (blue line). How i can find that the blue line is betweem the ray 35 and the ray 36? Now I can say it only by looking the plot.

回答(1 个)

Image Analyst
Image Analyst 2019-7-11
Use pdist2() on the separate x and y coordinates of the two line vectors. (Note: Requires stats toolbox):
distances = pdist2([x1(:),y1(:)], [x2(:),y2(:)]);
minDistance = min(distances(:))
[rows, columns] = find(distances == minDistance);
fprintf('These points are closest (%f, %f) of curve 1 and (%f, %f) of line 2.\n',...
x1(rows(1)), y1(rows(1)), x2(columns(1)), y2(columns(1)));

Community Treasure Hunt

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

Start Hunting!

Translated by