How to find two most distant points?

后端 未结 9 1961
旧巷少年郎
旧巷少年郎 2020-11-29 19:05

This is a question that I was asked on a job interview some time ago. And I still can\'t figure out sensible answer.

Question is:

you are given set of points

相关标签:
9条回答
  • 2020-11-29 20:06

    Find the mean of all the points, measure the difference between all points and the mean, take the point the largest distance from the mean and find the point farthest from it. Those points will be the absolute corners of the convex hull and the two most distant points. I recently did this for a project that needed convex hulls confined to randomly directed infinite planes. It worked great.

    See the comments: this solution isn't guaranteed to produce the correct answer.

    0 讨论(0)
  • 2020-11-29 20:06

    Just a few thoughts:

    You might look at only the points that define the convex hull of your set of points to reduce the number,... but it still looks a bit "not optimal".

    Otherwise there might be a recursive quad/oct-tree approach to rapidly bound some distances between sets of points and eliminate large parts of your data.

    0 讨论(0)
  • 2020-11-29 20:07

    Boundary point algorithms abound (look for convex hull algorithms). From there, it should take O(N) time to find the most-distant opposite points.

    From the author's comment: first find any pair of opposite points on the hull, and then walk around it in semi-lock-step fashion. Depending on the angles between edges, you will have to advance either one walker or the other, but it will always take O(N) to circumnavigate the hull.

    0 讨论(0)
提交回复
热议问题