简体   繁体   English

找到与平面中所有其他点不共线的点

[英]find a point non collinear with all other points in a plane

Given a list of N points in the plane in general position (no three are collinear), find a new point p that is not collinear with any pair of the N original points.给定一般平面 position 中的 N 个点列表(没有三个点共线),找到与 N 个原始点中的任何一对都不共线的新点 p。

We obviously cannot search for every point in the plane, I started with finding the coincidence point of all the lines that can be formed with the given points, or making a circle with them something.. I dont have any clue how to check all the points.我们显然不能搜索平面上的每个点,我开始寻找可以与给定点形成的所有线的重合点,或者用它们做一个圆圈......我不知道如何检查所有点。

Question found in http://introcs.cs.princeton.edu/java/42sort/http://introcs.cs.princeton.edu/java/42sort/中发现的问题

I found this question in a renowned algorithm book that means it is answerable, but I cannot think of an optimal solution, thats why I am posting it here so that if some one knows it he/she can answer it我在一本著名的算法书中发现了这个问题,这意味着它是可以回答的,但我想不出一个最佳解决方案,这就是为什么我把它贴在这里,这样如果有人知道他/她就可以回答它

The best I can come up with is an N^2 algorithm.我能想到的最好的是 N^2 算法。 Here goes:开始:

  1. Choose a tolerance e to control how close you're willing to come to a line formed from the points in the set.选择一个公差e来控制您愿意接近由集合中的点形成的线的程度。
  2. Compute the convex hull of your set of points.计算点集的凸包
  3. Choose a line L parallel to one of the sides of the convex hull, at a distance 3e outside the hull.选择一条线 L 平行于凸包的一侧,距离凸包3e
  4. Choose a point P on L, so that P is outside the projection of the convex hull on L. The projection of the convex hull on L is an interval of L. P must be placed outside this interval.在L上选择一点P,使得P在凸包在L上的投影之外。凸包在L上的投影是L的一个区间。P必须在这个区间之外。
  5. Test each pair of points in the set.测试集合中的每一对点。 For a particular line M formed by the 2 test points intersects a disc of radius 2e around P, move P out further along L until M no longer intersects the disc.对于由 2 个测试点形成的特定线 M 与围绕 P 的半径为2e的圆盘相交,将 P 沿 L 进一步移出,直到 M 不再与圆盘相交。 By the construction of L, there can be no line intersecting the disk parallel to L, so this can always be done.通过 L 的构造,不可能有与平行于 L 的圆盘相交的线,所以这总是可以做到的。
  6. If M crosses L beyond P, move P beyond that intersection, again far enough that M doesn't pass through the disc.如果 M 越过 L 越过 P,将 P 移过该交点,再次移动到足以使 M 不穿过圆盘。
  7. After all this is done, choose your point at distance e , on the perpendicular to L at P. It can be colinear with no line of the set.完成所有这些后,选择距离e处的点,在 P 处与 L 垂直。它可以与集合中的任何一条线共线。

I'll leave the details of how to choose the next position of P along L in step 5 to you,具体如何在第5步中选择P沿L的下一个position留给你,

There are some obvious trivial rejection tests you can do so that you do more expensive checks only with the test line M is "parallel enough" to L.您可以执行一些明显的琐碎拒绝测试,以便仅在测试线 M 与 L“足够平行”时进行更昂贵的检查。

Finally, I should mention that it is probably possible to push P far enough out that numerical problems occur.最后,我应该提一下,将 P 推得足够远可能会出现数值问题。 In that case the best I can suggest is to try another line outside of the convex hull by a distance of at least 3e .在那种情况下,我能建议的最好的办法是在凸包外尝试另一条线,距离至少为3e

You can actually solved it using a simple O(nlogn) algorithm, which we will then improve to O(n).您实际上可以使用简单的 O(nlogn) 算法解决它,然后我们将其改进为 O(n)。 Name A the bottom most point (in case of tie choose the one that is has smaller x coordinate).将 A 命名为最底部的点(如果出现平局,请选择 x 坐标较小的点)。 You can now sort in clockwise order the rest of the points using the CCW.您现在可以使用 CCW 按顺时针顺序对点的 rest 进行排序。 Now as you process each point from the sorted order you can see that between any two successive points having different angle with point A and the bottom axis (let these be U, V) there is no point having angle c, with U <= c <= V. So we can add any point in this section and it is guaranteed that it won't be collinear with any other points from the set.现在,当您处理排序顺序中的每个点时,您可以看到在与点 A 和底轴(假设它们是 U、V)具有不同角度的任何两个连续点之间,没有角度为 c 的点,其中 U <= c <= V。所以我们可以在这个部分添加任何点,并且保证它不会与集合中的任何其他点共线。 So, all you need is to find one pair of adjacent points and you are done.所以,你只需要找到一对相邻的点就可以了。 So, find the minimum and the second minimum angle with A (these should be different) in O(n) time and select any point in between them.因此,在 O(n) 时间和 select 之间的任何点中找到与 A 的最小和第二个最小角度(这些应该不同)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM