I have a problem as described in the title and I am using MATLAB 2020.
I have 2 sets of 2D points, and I want to find the two points (each point from a different set)
that has the minimal distance from all the other points min(distance(pi,pj))
I done some research (google) and found this article:
"Optimal Algorithms for Computing the Minimum Distance Between Two Finite Planar Sets"
in this web page:
What is the fastest algorithm to calculate the minimum distance between two sets of points?
I tried to implement the algorithm, using MATLAB, and a code for Garbriel graph (which I found in google) here:
http://matgeom.sourceforge.net/doc/api/matGeom/graphs/gabrielGraph.html
the problem is that when I run the code,which suppose to be the algorithm vs a "brute force algorithm" (two loops) , the brute force is always faster... no matter how many points I used , and it is way faster... which is in contrast to logic (mine) and the article mention above.
when I check the execution time of the code lines, I found that the line
dist = dist + (repmat(p1(:,i), [1 n2])-repmat(p2(:,i)', [n1 1])).^2;
in :
minDistancePoints(p1, varargin)
is the "problem" and advises? thank you
p.s let
set1=random(100,2)
set2=random(100,2)
i want to find the point1 in set1 and the point2 in set2 that have minimum distance from all the other points.
delaunayn
. You should just build on top ofdelaunayn
directly. – David Eisenstat