Problem 51. Find the two most distant points
Given a collection of points, return the indices of the rows that contain the two points most distant from one another. The input vector p has two columns corresponding to the x and y coordinates of each point. Return ix, the (sorted) pair of indices pointing to the remotest rows. There will always be one unique such pair of points.
So if
p = [0 0] [1 0] [2 2] [0 1]
Then
ix = [1 3]
That is, the two points p(1,:) and p(3,:) are farthest apart.
Solution Stats
Problem Comments
-
7 Comments
More easy that it seems.
You need to specify "Euclidean" distance :-)
Good problem, not too hard but required thinking
Please add the next test :
p = [0,0;
2,1;
2,6;
1,6];
ix_correct = [1 3];
assert(isequal(mostDistant(p),ix_correct))
The solutions of the form:
[~,indx]=max(dist(p'));
unique(indx)
will fail, the last line will return an extra index [1,3,4] instead of just [1,3]
refer to
Convex Hull therom and the Graham's Scan method
+1
Nice one!
Solution Comments
Show commentsProblem Recent Solvers2834
Suggested Problems
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15528 Solvers
-
Remove the polynomials that have positive real elements of their roots.
1673 Solvers
-
Convert a numerical matrix into a cell array of strings
1830 Solvers
-
What is the distance from point P(x,y) to the line Ax + By + C = 0?
372 Solvers
-
Find the index of the largest value in any vector X=[4,3,4,5,9,12,0,4.....5]
378 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!