Minimal distance between several points.
DIST = minDistancePoints(PTS)
Returns the minimum distance between all pairs of points in PTS. PTS
is a N-by-D array of values, N being the number of points and D the
dimension of the points.
DIST = minDistancePoints(PTS1, PTS2)
Computes for each point in PTS1 the minimal distance to every point of
PTS2. PTS1 and PTS2 are N-by-D arrays, where N is the number of points,
and D is the dimension. Dimension must be the same for both arrays, but
number of points can be different.
The result is an array the same length as PTS1.
DIST = minDistancePoints(..., NORM)
Uses a user-specified norm. NORM=2 means euclidean norm (the default),
NORM=1 is the Manhattan (or "taxi-driver") distance.
Increasing NORM growing up reduces the minimal distance, with a limit
to the biggest coordinate difference among dimensions.
[DIST, I, J] = minDistancePoints(PTS)
Returns indices I and J of the 2 points which are the closest. DIST
verifies relation:
DIST = distancePoints(PTS(I,:), PTS(J,:));
[DIST, J] = minDistancePoints(PTS1, PTS2, ...)
Also returns the indices of points which are the closest. J has the
same size as DIST. It verifies relation:
DIST(I) = distancePoints(PTS1(I,:), PTS2(J,:));
for I comprised between 1 and the number of rows in PTS1.
Examples:
% minimal distance between random planar points
points = rand(20,2)*100;
minDist = minDistancePoints(points);
% minimal distance between random space points
points = rand(30,3)*100;
[minDist ind1 ind2] = minDistancePoints(points);
minDist
distancePoints(points(ind1, :), points(ind2, :))
% results should be the same
% minimal distance between 2 sets of points
points1 = rand(30,2)*100;
points2 = rand(30,2)*100;
[minDists inds] = minDistancePoints(points1, points2);
minDists(10)
distancePoints(points1(10, :), points2(inds(10), :))
% results should be the same
% Find the (approximated) orthogonal projection onto an ellipse
elli = [50 50 40 20 30];
poly = ellipseToPolygon(elli, 200);
figure; axis equal; axis([0 100 0 100]); hold on;
drawPolygon(poly, 'k')
pts = [20 20; 50 20; 80 30];
[dists, inds] = minDistancePoints(pts, poly);
drawPoint(pts, 'bo');
drawPoint(poly(inds,:), 'ko');
drawEdge([pts poly(inds,:)], 'k')
See Also
points2d, distancePoints, nndist, findClosestPoint, hausdorffDistance
Package: matgeom