Patra2012 Convexhull Report
Patra2012 Convexhull Report
on
Chan’s convex hull algorithm
by
Sunandita Patra
Roll number: 09CS3037
3rd year Dual degree student
Computer Science and Engineering
IIT Kharagpur
Email: [email protected],
[email protected]
The problem
The convex hull problem is, given a set of n points, P in the 2D plane, we have to find a representation
of P’s convex hull. The convex hull is a closed convex polygon. It can be represented simply with the
help of counterclockwise or clockwise enumeration of the vertices of the convex hull. Ideally, the
vertices of the hull should be extreme points, in the sense that if three points lie on an edge of the
boundary of the convex hull, then the middle point should not be reported as a vertex of the hull. Thus,
any algorithm to find the convex hull of a point said should have the following form:
Output The vertices of the convex hull of P, in clockwise or counter clockwise order
Towards a solution
Here is a list of some well-known 2D hull algorithms (from reference [5]). The notation used is n =
number of points in the input set, P and h = number of vertices on the convex hull. The list is ordered
by date of first publication.
Observation 1
Suppose a point, p lies on the convex hull of a set of n points, P. Then, p will also be a point on the
convex hull of any subset of P containing p. Thus, a point that does not lie on any subhull of any subset
of P containing p, it can never lie on the convex hull of P.
Observation 2
We reduce the number of candidates by grouping the points into several groups and finding their
convex hulls. Now, only these hull vertices are candidates to be vertices of the convex hull of P. The
convex hull of these smaller convex hulls is the convex hull of P. The interior points of these subhulls
need not be considered in future steps.
Observation 3
It turns out that in the worst-case, convex hulls cannot be computed faster than in O(nlogn) time. One
way to see this intuitively is to observe that the convex hull itself is sorted along its boundary, and
hence if every point lies on the hull, then computing the hull requires sorting of some form. Yao proved
the much harder result that determining which points are on the hull (without sorting them along the
boundary) still requires O(nlogn) time. However, both of these results rely on the fact that all (or atleast
a constant fraction) of the points lie on the convex hull. This is often not true in practice.
The Quick Hull and Jarvis’s March algorithms suggest the question of how fast can convex hulls be
computed if we allow the running time to be described in terms of both the input size n and the output
size h. Many geometric algorithms have the property that the output size can be a widely varying
function of the input size, and worst-case output size may not be a good indicator of what happens
typically. An algorithm which attempts to be more efficient for small output sizes is called an output
sensitive algorithm, and running time is described as an asymptotic function of both input size and
output size.
We can observe that any convex hull algorithm must take at least O(n) time (we have to look at each
point atleast once), and given that “log n” factor arises from the fact that you need to sort the at most n
points on the hull, if you were told that there are only h points on the hull, then a reasonable target
running time is O(n log h). (We will see that this is optimal.)
Kirkpatrick and Seidel discovered a relatively complicated O(n log h) time algorithm, based on a clever
pruning method in 1986. About 10 years later, Timothy Chan came up with a much simpler algorithm
with the same running time. One of the interesting aspects of Chan’s algorithm is that it involves
combining two slower algorithms (Graham’s scan and Jarvis’s March) together to form an algorithm
that is faster than either one.
The problem with Graham’s scan is that it sorts all the points, and hence will always have an Ω (n log n)
running time, irrespective of the size of the hull. On the other hand, Jarvis’s march can perform better if
you have few vertices on the hull, but it takes Ω (n) time for each hull vertex.
Chan’s idea was to partition the points into groups of equal size. There are a maximum of m points in
each group, and so the number of groups is k = ceiling (n/m). For each group, we compute its hull using
Graham’s scan, which takes O(m log m) time per group, for a total time of O(km log m) = O(n log m).
Thus, after this step, we have k subhulls. Note that since the points in a set were selected arbitrarily,
these subhulls may intersect with each other, one may completely lie within another, or they may be
disjoint.
Next, we use the Jarvis march algorithm (to compute convex hull of a 2D point set) on the groups. Here
we take advantage of the fact that you can compute the tangent between a point and a convex m-gon in
O(log m) time.
The idea is to find the next vertex of the convex hull, pi+1 by knowing a current vertex, pi. We select the
leftmost point among all the vertices of all the subhulls. This point is guaranteed to be in the convex
hull of P. We name this point as p0, i = 0. Then, we find the tangents from pi to each of the subhulls. The
tangent which makes the lowest angle with pipi-1, its point of contact with the subhull will surely be the
next vertex of the convex hull of P.
Without loss of generality, we can assume that the vertices of the convex hull are ordered in
clockwise direction. We perform a binary search on the list of vertices, choosing sides by
calculating the angles made by the edge qpi with the two edges which contain the point, pi. pi is
the point of tangency if the two edges containing pi lie on the same side of qpi. This new line
segment is the corresponding tangent.
We repeat until the newly found hull vertex coincides with p0.
So, as before there are h steps of Jarvis’s march, but because we are applying it to k convex hulls each
step takes O (k log m) time. Each iteration consists of finding a tangent using binary search O(log m) and
then finding the tangent which makes the least angle with the current edge of the convex hull (O(k)).
Thus, the cost of each iteration = O(klogm) and total running time = O(hk log m) = O((hn/m) log m).
Combining the two parts, we get a total of O((n + hn/m) log m) running time.
We can observe that if we set m = h, we can get O(n log h) running time. There is only one small
problem here. We do not know what h is in advance, and therefore we do not know what m should be
when running the algorithm. We will see how to take care of this later. The algorithm works correctly
as long as m >= h.
1. Let k = ceiling (n/m). Partition P into disjoint subsets such that ⋃ , each of size at
most m.
2. For i = 1 to k do:
(a) Compute convex hull(Pi) using Graham’s scan and store the vertices in an
ordered array.
The remaining thing is choosing the value of m correctly. We can choose m to be 1, 2, 3 and so on, till
we get m >= h. But this will increase the time complexity. Binary search will definitely be more efficient
than this but if we use binary search, we may guess too large value of m (for example, m = n/2 = O(n)),
which will in turn increase the time to O(n log n)
So, Chan uses the trick that we start with a small value of m and increase it rapidly. Since the
dependence on m is only in the logarithmic term, as long as our value of m is within a polynomial of h,
that is, m = ch for some constant c, (in other words m = O(h)) then the running time will still be O(n log
h). So, our approach will be to guess successively larger values of m, each time squaring the previous
value, until the algorithm returns a successful result. This technique is often called doubling search
(because the unknown parameter is successively doubled). The only difference is that in Chan’s
algorithm, we will be squaring the old value rather than doubling.
1. For t = 1, 2, 3, … do:
a. Let m = min( )
b. Invoke Partial Hull (P, m), returning the result in L.
c. If L “failure”, then return L.
We should note that has the effect of squaring the previous value of m.
For the t-th iteration, running time = O(nlog(mt)) = O(n log ) = O(n ). We know that it will stop as
soon as > h, that is if t = ceiling(lg(lg n)). So, the total running time is
∑ ∑
The storage requirement is clearly linear because we are storing only the vertices of the convex hull
which is linear to the total number of points in the input, n.
References:
1. Timothy M. Chan: Optimal Output Sensitive Convex Hull Algorithms in Two and Three Dimensions.
Discrete Computational Geometry 16:361-368 (1996)
2. http://en.wikipedia.org/wiki/Chan's_algorithm
3. Chris Harrison. An Investigation of Graham's Scan and Jarvis'
March URL:http://www.chrisharrison.net/projects/convexHull/index.html
4. http://softsurfer.com/Archive/algorithm_0201/algorithm_0201.htm#tangent_PointPolyC()
5. http://www.tcs.fudan.edu.cn/rudolf/Courses/Algorithms/Alg_cs_07w/Webprojects/Zhaobo_hull/index.ht
ml
6. Lecture notes by David M. Mount