我有興趣實施和學習Kirkpatrick–Seidel algorithm。 這是尋找一些點集的凸包的分而治之的方法。我只關心二維情況。征服之前的婚姻執行問題凸包算法
我發現了一個有趣的講義有關此問題here:是
該算法的一般步驟如下:
INPUT: A set P of points on the plane.
OUTPUT: The set of points that define the convex hull.
1. Calculate median x-coordinate M of P.
2. Find the bridge segment that crosses the line x = M using the
Prune and Search Technique.
3. Trim the set based on this segment
4. Split P to sets PL, PR and recursively apply the above steps to find
the remaining segments
5. The above steps must be run twice, once for the upper hall and once
for the lower hall. Once you find both, you have the convex hull.
(1)可以在O(N)中找到。這是非常平凡的,特別是在C++中,你可以使用nth_element
與指定比較器
(3)也可以在O(N)中找到。如果您發現由點p1
和p2
確定的段,那麼你只需要忽略每個點p
其中p1.x <= p.x <= p2.x
(4)只是(3)
的直接結果( 5)在剛發現的兩個子集上進行兩次遞歸調用
爲了從這個分而治之算法中實現O(nlogn)
的複雜性。我們需要步驟(2)也取O(n)
。
根據講義,這一步可以通過線性規劃來解決,並且由於我們在飛機上工作,所以可以實現線性時間。
現在,講義將更詳細地解釋部分(2),這裏是步驟。
我明白除了每一個步驟(3)和(4)。
(3)。什麼是b
?我想這沒關係。既然你已經找到了斜率m
,然後繼續找到設置P的支撐線。B是你正在尋找的東西。
(4)。 P組的支持線以及如何有效地找到它?