给定一组点,如何找到彼此最远的两个点?

发布于 2024-08-09 08:34:31 字数 293 浏览 12 评论 0 原文

可能的重复:
最大线性维度二维点集

我可以计算每个点之间的距离点并取最大的,但是当有大量(> 1000)点时,这听起来不是一种非常有效的方法。

注意:这是针对 iPhone 的,所以我没有太多的处理能力。

Possible Duplicate:
Greatest linear dimension 2d set of points

I could compute the distance between each point and take the largest but that doesn't sound like a very efficient way to do it when there are a large (> 1000) number of points.

Note: This is for iPhone so I don't have a ton of processing power.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

羅雙樹 2024-08-16 08:34:31

为什么不直接计算点的凸包?根据您使用的算法,它需要O(n)O(n log n) 时间,并消除所有内部点的考虑。然后,仅检查这些最外面的点以找到距离最远的两个点。

Why not just compute the convex hull of the points? Depending on the algorithm you use, it takes either O(n) or O(n log n) time and eliminates all the inner points from consideration. Then, only check these outermost points to find the two that are the farthest away.

冬天旳寂寞 2024-08-16 08:34:31

您要求计算该集合的直径。标准技术是首先计算凸包,这将问题简化为查找凸多边形的直径。即使在不消除任何点的情况下,这些添加的信息也正是有效解决问题所需要的。然而,求出凸多边形的直径并不是一件容易的事。几篇发表的关于此任务的算法的论文被证明是不正确的。

这是相当可读的讨论 任务的正确 O(n) 算法(其中 n 是凸包中的点数)。

另请注意,iPhone 并不受此限制。即使是完全简单的算法,精心编写的实现也可以在不到十分之一秒的时间内处理 1000 个点。当然,使用正确的算法会让你走得更快 =)

You're asking to compute the diameter of the set. The standard technique is to first compute the convex hull, which reduces the problem to finding the diameter of a convex polygon. Even in the case where you don't eliminate any points, this added information is exactly what's needed to solve the problem efficiently. However, finding the diameter of a convex polygon is not entirely trivial; several published papers with algorithms for this task turn out to be incorrect.

Here's a fairly readable discussion of a correct O(n) algorithm for the task (where n is the number of points in the convex hull).

Also, note the the iphone isn't that limited; a carefully written implementation of even the completely naive algorithm can handle 1000 points in less than a tenth of a second. Of course, using the correct algorithm will let you go much faster =)

情独悲 2024-08-16 08:34:31

从 x 坐标最低的点开始。 (称之为X点)
构造“边界点”集
从点 x 开始,通过该点的垂直线,PointX 左侧不应有其他点)通过顺时针(或逆时针)缓慢旋转线找到边界中的下一个点,直到线接触其他点,(见下文)。将该点添加到集合中,并重复下一个点以获得下一个点,直到最终回到原始点 x。你有一组点形成完整集合的边界。比较该简化集合中每对之间的距离,以找到相距最远的对。

要“旋转线”(以找到每个连续边界点),请取与最后一个边界点所用线垂直的方向“最远”的点,并在最后一个边界点和该“下一个”点。然后验证在该新线形成的新垂直方向上是否没有其他点。如果在垂直于这条线或最后一条线的方向上没有其他点“进一步向外”,那么这是下一个边界点的正确选择,如果存在这样的点,则切换到该点并重新测试。

Start with point with lowest x-coord. (Call it Point X)
Construct set of "boundary points"
starting with point x, and vertical line through the point, There should be no other points to left of PointX) find the next point in boundary by slowly rotating the line clockwise (Or counterclockwise) until the line touches some other point, (see below). Add that point to the set and repeat with that next point to get the next one, until you eventually get back to the original point x. You npw have a set of points forming the boundary of the complete set. Compare distance between each pair in this reduced set to find the pair that are furthest apart.

To "rotate the line" (to find each sequential boundary point), take the point which is "furthest" in the direction perpindicular to the line used for the last boundary point, and construct a new line between the last boundary point and that "next" point. Then verify that there are no other points furthur in the new perpindicular direction formed by that new line. If there are no other points "furthur out" in the dirtection perpindicular to this line or to the last line, then this is the right cjhoice for the next boundary point, if there is such a point, switch to that one and retest.

入画浅相思 2024-08-16 08:34:31

请参阅这些页面(链接到和单击“下一个”链接可访问的页面)计算一组点的凸包直径。

我的快速总结:

  1. 计算凸包中的点集(= O(n log n),唯一获得 O(n) 的时间是如果您首先对列表进行排序,无论如何都需要 O(n log n))
  2. 沿边界顺序(如果您使用 Graham 扫描 #1),您可以免费获得此
  3. 功能之一 ) (n) 直径算法,用于扫描具有最大直径的对映点。 Shamos 算法 对我来说看起来不错,因为它是 旋转卡尺算法。

See these pages (the one linked to and the pages reachable by clicking on the "next" links) on computing the diameter of the convex hull of a set of points.

My quick summary:

  1. compute set of points in convex hull (= O(n log n), the only time you get O(n) is if you sort the list first which takes O(n log n) anyway)
  2. order along boundary (you get this for free if you use a Graham scan for #1)
  3. use one of the O(n) diameter algorithms to scan for antipodal points with greatest diameter. Shamos algorithm looks good to me as it's one of the rotating calipers algorithms.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文