转载:平面点集凸壳算法大全(英文)

326 篇文章 2 订阅
20 篇文章 0 订阅
转载自:http://www.tcs.fudan.edu.cn/rudolf/Courses/Algorithms/Alg_cs_07w/Webprojects/Zhaobo_hull/#section26

1. Introduction

convexhull

We are given a set P of n points in the plane. We can define the convex hull of P, that is CH(P), as the largest convex polygonwhose vertices are all points in P, or the unique convex polygon that contains P and whose vertices are all points in P. There are two main properties of convex hulls:

  • One of these properties is that all of the points in the final polygon must be indented outwards, or more formally, convex. If any points are concave, there exists a better path by excluding that point, and drawing a direct line between its two neighbor points, which reduces the overall perimeter point count by one. This property is exploited by Graham's Scan, a pioneering algorithm for convex hulls covered later in the paper.

  • Another important property is that the most extreme point on any axis is part of the convex hull. This fact is apparent if you consider an example in which an extreme point is not in the convex hull. This would mean the perimeter of the convex hull passes through a point less extreme than that point. However, it is then obvious that the extreme point would not be included in the enclosed set, thus voiding a fundamental characteristic of convex hulls. This property is used by a number of algorithms because they rely on information computed from an initial point in the convex hull[1].

Computing a convex hull (or just "hull") is one of the first sophisticated geometry algorithms, and there are many variations of it. The most common form of this algorithm involves determining the smallest convex set (called the "convex hull") containing a discrete set of points.

The most popular algorithms are the "Graham scan" algorithm [Graham, 1972] and the "divide-and-conquer" algorithm [Preparata & Hong, 1977]. Implementations of both these algorithms are readily available (see [O'Rourke, 1998]). Both are O(n log n) time algorithms, but the Graham has a low runtime constant in 2D and runs very fast there. However, the Graham algorithm does not generalize to 3D and higher dimensions whereas the divide-and-conquer algorithm has a natural extension. We do not consider 3D algorithms here (see [O'Rourke, 1998] for more information)[2].


2. Algorithms


 

If the java applet could not run normally, please install SUN JRE 1.4 or higher version.



2.1 Brute force

This is a simple O(n3) convex hull algorithm, which operates by considering each ordered pair of points (p, q),and then determining whether all the remaining points of the set lie within the half-plane lying to the right of thedirected line from p to q.

Back to home

2.2 Graham's scan
simplepolygon

The Graham's Algorithm first explicitly sorts the points in O(nlogn) and then applies a linear-time scanning algorithm to finish building the hull.

We start Graham's scan by finding the leftmost point l. We connect l with all the other points, then according to the angles in polar coordinates of the lines, we connect the points in couterclockwise order, starting and ending at l. Now we get a simple polygon with n vertices.

To change this polygon into convex hull, we apply the three-penny algorithm,the scanning phase takes O(n) time altogether. So the total time is O(nlogn)

Back to home

2.3 Jarvis's march(gift wrapping)
Jarvis'march

Jarvis's match algorithm is like wrapping a piece of string around thepoints. It starts by computing the leftmost point l, since we know that the left most point must be a convex hull vertex.This processwill take linear time.Then the algorithm does a series of pivoting steps to find each successive convex hull vertex untill the next vertex is the original leftmost point again.

The algorithm find the successive convex hull vertex like this: the vertex immediately following a point p is the point that appears to be furthest to the right to someone standing atp and looking at the other points. In other words, if q is the vertex following p, and r is any other input point, then thetriple p, q, r is in counter-clockwise order. We can find each successive vertex in linear time by performing a series of O(n) counter-clockwise tests.

Since the algorithm spends O(n) time for each convex hull vertex, the worst-case running time is O(n2). However, if the convex hull has very few vertices, Jarvis's march is extremelyfast. A better way to write the running time is O(nh), where h is the number of convex hull vertices. In the worst case, h = n, and we get our old O(n2) time bound, but in the best case h = 3, and the algorithm only needs O(n) time. This is a so called output-sensitive algorithm, the smaller the output, the faster the algorithm.

Back to home

2.4 Divide-and-Conquer

This is another O(nlogn) time algorithm , which is based on the divide and conquer design technique. It can be viewed as a generalization of the MergeSort sorting algorithm. It begins by sorting the pointsby their x coordinate, in O(nlogn) time. The remainder of the algorithmis shown below.

  1. If |P|<=3 then compute the convex hull by brute force in O(1) time and return.
  2. Otherwise, partition the point set P into two sets L and R, where L consists of half the points with the lowest x coordinates and R consists of half of the points with the highest x coordinates.
  3. Recursively compute HL = CH(L) and HR = CH(R).
  4. Merge the two hulls into a common convex hull, H, by computing the upper and lower tangents for HL and HR and discarding all the points lying between these two tangents.

Back to home

2.5 Quick hull
quickhull

Like the divide-and-conquer algorithm can be viewed as a sort of generalization of MergeSort, the QuickHull algorithm can be thought of as a generalization of the QuickSort sorting procedure. Like QuickSort , this algorithm runs in O(nlogn) time for favorable inputs but can take as long as O(n2) time for unfavorable inputs.

The idea behind QuickHull is to discard points that are not on the hull as quickly as possible. QuickHull begins by computing the points with the maximum and minimum, x- and y- coordinate. Clearly thesepoints must be on the hull, and connect the four points we get a convex quadrilateral, all the points within this quadrilateral canbe eliminated from further consideration. All of this can be done in O(n) time.



Back to home

2.6 Chan's algorithm(output sensitivity)
chan_one

This is another output-sensitive algorithm, which was discoverd by Timothy Chan in 1993, the running time is O(nlogh). Chan's algorithm involves cleverly combining two slower algorithms, that is , Graham's scan and Jarvis's March,to form an algorithm that is faster than either one.

First suppose we know there are h points on the convex hull, this algorithm starts by shattering the input points in n/h arbitray subsets, each of size h, and computing the convex hull of each subset using (say) Graham's scan. This much of the algorithm requires O((n/h)hlogh) = O(nlogh) time.

Once we have the n/h subhulls, we follow the general outline of Javis'smarch, wrapping a string around the n/h subhulls. Start with the leftmost input point l, starting with p = l we successively find the convex hull vertexes in counter-clockwise order until we return back to the original leftmost point again.

The successor of p must lie on a right tangent line between p and one of the subhulls, a line from p through a vertex of the subhull, such that the subhull lies completely on the right side of the line from p's point of view. We can find the right tangent line between p and any subhull in O(logh) time using a variant of binary search. Since there are n/h subhulls, finding the successor of p takes O((n/h)logh) time together. Since there are h convex hull edges, and we find each edge in O((n/h)logh) time, the overall running time of the algorithm is O(nlogh).

Unfortunately, this algorithm only takes O(nlogh) time if we know the value of h in advance. So how do we know h's value? Chan's trick is to guess the correct value of h, let's denote the guess by h'.Then we shatter the points into n/h' subsets of size h', compute their subhulls, and then find the first h' edges of the globalhull. If h < h', this algorithm computes the complete convex hull in O(nlogh') time. Otherwise, the hull doesn't wrap all theway back around to l, so we know our guess h' is too small.

Chan's algorithm starts with the optimistic guess h' = 3. If we finish an iteration of the algorithm and find that h' is too small, we square h' and try again. In the final iteration, h'<h2, so the last iteration takes O(nlogh') = O (nlogh2) = O(nlogh) time.

The total running time of Chan's algorithm is given by the sum: O(nlog3 + nlog32 + nlog34 + ... + nlog32k) , for some integer k. We can rewrite this as a geometric series: O(nlog3 + 2nlog3 + 4nlog3 + ... + 2knlog3). So Chan's algorithm runs in O(nlogh) time overall, even we don't know the value of h.

In the figures, in order to keep things as clear as possible, the original author [6] have chosenthese subsets so that their convex hulls are disjoint. This is not true in general.

chan_two







Back to home





2.7 Incremental

The incremental convex hull algorithm are usually relatively simple to implement, and generalize well to higher dimensions. This algorithm operates by inserting points one at a time and incrementally updating the hull. If the new point is inside the hull there is nothing to do. Otherwise, we must delete all the edges that the new point can see.Than we connect the new point to its two neighbor points to update the hull. By repeating this process for the rest points outsidethe hull, finally, we get the convex hull for the points set

The randomized version of the algorithm operates as follows. Permute the points randomly,let P = (p0, p1,..., pn-1) be this sequence. Let H2 = CH(p0, p1, p2)(a triangle). For i running from 3 to n-1, insert pi into the existing hull Hi-1.

As with other randomized algorithms, the expected running time depends on the random order of insertion, but is independent of the point set. By a backwards analysis, we can know its running time is O(nlogn).

Back to home

2.8 Monotone Chain
monotone

Andrew's Monotone Chain Convex Hull algorithm is an algorithm which constructs convex hull of a set of 2D points in O(nlogn) time. It does this by first sorting the points lexicographically (first by x-coordinate, and in case of a tie, by y-coordinate), and then constructing upper and lower hulls of the points in O(n) time. An upper hull is the part of the convex hull, which is visible from the above. It runs from its rightmost point to the leftmost point in counterclockwise order. Lower hull is the remaining part of the convex hull.





Back to home

2.9 Running time comparision

Algorithm Running Time Discovered By
Brute Force O(n3) ——
Graham Scan O(nlog n) Graham, 1972
Jarvis March O(nh) Jarvis, 1973
QuickHull O(nh) Eddy, 1977 ; Bykat, 1978
Divide-and-Conquer O(nlog n) Preparata & Hong, 1977
Monotone Chain O(nlog n) Andrew, 1979
Incremental O(nlog n) Kallay, 1984
Chan's algorithm O(nlog h) Timothy Chan, 1993

Back to home

3. Related algorithms
3.1 Onions-peeling

Consider a set S of n on the plane. Compute the convex hull of S, and let S' be the set of points remaining in the interior of the hull. Then compute the convex hull of S' and recursively repeat this process until no more points remain. One ends up with a sequence of nested convex hulls, called the onion-peeling of S[4].

We have a simple algorithm to compute the onion-peeling of the point set S.

  1. Sort all points of S by x-coordinate.
  2. Run an algorithm which could compute the convex hull of S in time O(n), such as Graham's Scan, to get the convex hull H of S.
  3. Remove the vertices of H from S. If |S|>2, repeat step 2; else finished.

The sort process takes time O(nlogn). Each process of compute the convex hull takes time O(n), and in the worst case, each convex hull H computed is a triangle, in which case we need O(n) iterations. So, the total running time is O(n2). There is a sophiscatied and complicated algorithm that computes the onion in time O(nlogn) , thanks to Chazelle [3].

Note that the innermost structure can either be a line segment or a single point, besides a convex polygon. This graph gives information as to the layering of the points, i.e. how "deep" points are relative to each other other.

Back to home

3.2 Onion triangulations

The region between two nested convex hulls is called an annulus. Toussaint (1986) presents a simple algorithm for triangulating an annulus, using the Rotating Calipers. Using his method, once the onion peeling has been obtained, the entire set can be triangulated in linear time. Furthermore, the triangulation has two advantages: it keeps the onion-peeling as a subgraph, and it is hamiltonian, that is the dual of the triangulation graph is a chain.

The algorithm for triangulating an annulus is quite simple. The input is assumed to be a convex hull Q nested in an other hull P, both given in clockwise order.

  1. Insert the edges of the hulls as edges in the triangulation.
  2. Compute the points with minimum x coordinate for both P and Q, calling them xmin(P) and xmin(Q).
  3. Construct two vertical lines of support (the calipers) at xmin(P) and xmin(Q); call them LP and LQ.
  4. Insert (xmin(P), xmin(Q)) as an edge in the triangulation.
  5. The "current" points p and q for LP and LQ are xmin(P) and xmin(Q), respectively.
  6. Rotate the lines clockwise until one coincides with an edge. A new vertex has therefore been "hit" by one of the lines.
    • If it belongs to P (call it p'), insert (p', q) into the triangulation. Update the "current" points to p' and q.
    • If it belongs to Q (call it q'), insert (p, q') into the triangulation. Update the "current" points to p and q'.
    • In case of parallel edges, both lines of support coincide with edges, and two new vertices are "hit" (call them p' and q'). Then, insert (p', q'), and either (p, q') or (p', q) into the triangulation. Update the "current" points to p' and q'.
  7. Repeat the previous step until the starting minimum points are reached.

The above algorithm has linear time complexity. When used to triangulate a set of points, a single convex hull is run (at most) twice through the procedure, once as the inner hull of the annulus, and once as the outer. Then the entire running time for triangulating a set of n points remains O(n)[4].

Back to home

3.3 Point location

A convex polygon P can be stored as an array of n vertices in sorted order along the boundary, a related question is about how can we test whether a query point q lies inside P?

Without loss of generality, let us assume that the points are in anticlockwise order (if not,we can simply access the elements of the array in reverse order). Let the points in the array be p1,p2, . . . ,pn. Let the first edge p1p2 be the reference edge; we will measure all angles with respect to this edge. We will use sector in the following way: take the diagonals from p1 to two adjacent vertices, extend them away from p1 into half-infinite lines, and the region between the two lines is a sector. Note that because P is convex, it is possible to draw lines to every other vertex from p1 without intersecting the exterior of P.

In general, what we seek to do is to perform a binary search for the sector that q lies in, and then test whether q lies in the triangle bounded by the edge opposite to p1 and the two rays defining the sector. The angle that a point s makes with the reference edge is which between the vectors p1p2 and p1s, denoted as the dot product[5]:

  1. If q = p1, then report that q is in the polygon immediately; else, continue.
  2. Calculate the angle that q makes with the reference edge, which denoted as θq.
  3. If θ≥ π, then report that q is outside the polygon; else, go to next step.
  4. If 0≤ θ< π, because the given vertices are in sorted order around P, the angle that successive vertices makewith the reference edgemust be non-decreasing; Therefore, the mapping from the elements of the array of points to angles relative to the reference edge results in a non-decreasing sequence of values (θ2,…,θn); Then, we can perform a binary search for largest θi≤θq, with three possibilities:
    • θq< 0 or θq> θn: the point lies outside of the possible range of angle values, and q cannot lie inside P.
    • θq= θi for some i: the point lies on a half-infinite ray from p1 to some other point. In this case, q lies inside P iff |p1q|≤|p1pi|.
    • θi< θq< θi+1 for some i: the point lies in the sector bounded by the half-infinite rays from p1 to pi and pi+1. If q lies inside P, then q must lie to the left of , so that it is possible to draw a line from p to q without going over the edge of . To do this, we can use the cross product; q lies inside P iff pointing out of the page (assuming a right-handed coordinate system).

The preprocessing steps are all O(1) operations. The binary search takes O(nlogn); note that we only need to calculate the mapping from points to angles for the points that we compare against in the binary search to avoid the O(n) cost of converting all the points. The post-processing after we have found the value of θi is O(1). In total, the query of whether q lies in P is O(nlogn).

Back to home

4. References
  1. Chris Harrison. An Investigation of Graham's Scan and Jarvis' March URL:http://www.chrisharrison.net/projects/convexHull/index.html
  2. Dan Sunday. The Convex Hull of a 2D Point Set or Polygon URL:http://www.softsurfer.com/Archive/algorithm_0109/algorithm_0109.htm
  3. Bernard Chazelle. On the convex layers of a planar set. In IEEE Transactions on Information Theory 31(4):509-517, 1995.
  4. Hormoz Pirzadeh's HomePage. URL:http://cgm.cs.mcgill.ca/~orm/ontri.html
  5. Enoch Lau. Computational Geometry: An Odyssey. COMP4045 Assignments. SID 200415765.
  6. Some of the pictures used in this page are from http://www.algorithmist.com/index.php/Monotone_Chain_Convex_Hull;http://www.cs.berkeley.edu/~jrs/274/hullErickson.ps
  7. The code of the java applet in this page made references from http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html and http://bo.majewski.name/bluear/cg/hull/hull.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值