Chan's algorithm
In computational geometry, Chan's algorithm,[1] named after Timothy M. Chan, is an optimal output-sensitive algorithm to compute the convex hull of a set of points, in 2- or 3-dimensional space. The algorithm takes time, where is the number of vertices of the output (the convex hull). In the planar case, the algorithm combines an algorithm (Graham scan, for example) with Jarvis march (), in order to obtain an optimal time. Chan's algorithm is notable because it is much simpler than the Kirkpatrick–Seidel algorithm, and it naturally extends to 3-dimensional space. This paradigm[2] has been independently developed by Frank Nielsen in his Ph.D. thesis.[3]
Algorithm[]
Overview[]
A single pass of the algorithm requires a parameter which is between 0 and (number of points of our set ). Ideally, but , the number of vertices in the output convex hull, is not known at the start. Multiple passes with increasing values of are done which then terminates when (see below on choosing parameter ).
The algorithm starts by arbitrarily partitioning the set of points into subsets with at most points each; notice that .
For each subset , it computes the convex hull, , using an algorithm (for example, Graham scan), where is the number of points in the subset. As there are subsets of points each, this phase takes time.
During the second phase, Jarvis's march is executed, making use of the precomputed (mini) convex hulls, . At each step in this Jarvis's march algorithm, we have a point in the convex hull (at the beginning, may be the point in with the lowest y coordinate, which is guaranteed to be in the convex hull of ), and need to find a point such that all other points of are to the right of the line [clarification needed], where the notation simply means that the next point, that is , is determined as a function of and . The convex hull of the set , , is known and contains at most points (listed in a clockwise or counter-clockwise order), which allows to compute in time by binary search[how?]. Hence, the computation of for all the subsets can be done in time. Then, we can determine using the same technique as normally used in Jarvis's march, but only considering the points (i.e. the points in the mini convex hulls) instead of the whole set . For those points, one iteration of Jarvis's march is which is negligible compared to the computation for all subsets. Jarvis's march completes when the process has been repeated times (because, in the way Jarvis march works, after at most iterations of its outermost loop, where is the number of points in the convex hull of , we must have found the convex hull), hence the second phase takes time, equivalent to time if is close to (see below the description of a strategy to choose such that this is the case).
By running the two phases described above, the convex hull of points is computed in time.
Choosing the parameter []
If an arbitrary value is chosen for , it may happen that . In that case, after steps in the second phase, we interrupt the Jarvis's march as running it to the end would take too much time. At that moment, a time will have been spent, and the convex hull will not have been calculated.
The idea is to make multiple passes of the algorithm with increasing values of ; each pass terminates (successfully or unsuccessfully) in time. If increases too slowly between passes, the number of iterations may be large; on the other hand, if it rises too quickly, the first for which the algorithm terminates successfully may be much larger than , and produce a complexity .
Squaring Strategy[]
One possible strategy is to square the value of at each iteration, up to a maximum value of (corresponding to a partition in singleton sets).[4] Starting from a value of 2, at iteration , is chosen. In that case, iterations are made, given that the algorithm terminates once we have
with the logarithm taken in base , and the total running time of the algorithm is
In three dimensions[]
To generalize this construction for the 3-dimensional case, an algorithm to compute the 3-dimensional convex hull by Preparata and Hong should be used instead of Graham scan, and a 3-dimensional version of Jarvis's march needs to be used. The time complexity remains .[1]
Pseudocode[]
In the following pseudocode, text between parentheses and in italic are comments. To fully understand the following pseudocode, it is recommended that the reader is already familiar with Graham scan and Jarvis march algorithms to compute the convex hull, , of a set of points, .
- Input: Set with points .
- Output: Set with points, the convex hull of .
- (Pick a point of which is guaranteed to be in : for instance, the point with the lowest y coordinate.)
- (This operation takes time: e.g., we can simply iterate through .)
- ( is used in the Jarvis march part of this Chan's algorithm,
- so that to compute the second point, , in the convex hull of .)
- (Note: is not a point of .)
- (For more info, see the comments close to the corresponding part of the Chan's algorithm.)
- (Note: , the number of points in the final convex hull of , is not known.)
- (These are the iterations needed to discover the value of , which is an estimate of .)
- ( is required for this Chan's algorithm to find the convex hull of .)
- (More specifically, we want , so that not to perform too many unnecessary iterations
- and so that the time complexity of this Chan's algorithm is .)
- (As explained above in this article, a strategy is used where at most iterations are required to find .)
- (Note: the final may not be equal to , but it is never smaller than and greater than .)
- (Nevertheless, this Chan's algorithm stops once iterations of the outermost loop are performed,
- that is, even if , it doesn't perform iterations of the outermost loop.)
- (For more info, see the Jarvis march part of this algorithm below, where is returned if .)
- for do
- (Set parameter for the current iteration. A "squaring scheme" is used as described above in this article.
- There are other schemes: for example, the "doubling scheme", where , for .
- If the "doubling scheme" is used, though, the resulting time complexity of this Chan's algorithm is .)
- (Initialize an empty list (or array) to store the points of the convex hull of , as they are found.)
- (Arbitrarily split set of points into subsets of roughly elements each.)
- (Compute the convex hull of all subsets of points, .)
- (It takes time.)
- If , then the time complexity is .)
- for do
- (Compute the convex hull of subset , , using Graham scan, which takes time.)
- ( is the convex hull of the subset of points .)
- (At this point, the convex hulls of respectively the subsets of points have been computed.)
- (Now, use a modified version of the Jarvis march algorithm to compute the convex hull of .)
- (Jarvis march performs in time, where is the number of input points and is the number of points in the convex hull.)
- (Given that Jarvis march is an output-sensitive algorithm, its running time depends on the size of the convex hull, .)
- (In practice, it means that Jarvis march performs iterations of its outermost loop.
- At each of these iterations, it performs at most iterations of its innermost loop.)
- (We want , so we do not want to perform more than iterations in the following outer loop.)
- (If the current is smaller than , i.e. , the convex hull of cannot be found.)
- (In this modified version of Jarvis march, we perform an operation inside the innermost loop which takes time.
- Hence, the total time complexity of this modified version is
- If , then the time complexity is .)
- for do
- (Note: here, a point in the convex hull of is already known, that is .)
- (In this inner for loop, possible next points to be on the convex hull of , , are computed.)
- (Each of these possible next points is from a different :
- that is, is a possible next point on the convex hull of which is part of the convex hull of .)
- (Note: depend on : that is, for each iteration , there are possible next points to be on the convex hull of .)
- (Note: at each iteration , only one of the points among is added to the convex hull of .)
- for do
- ( finds the point such that the angle is maximized[why?],
- where is the angle between the vectors and . Such is stored in .)
- (Angles do not need to be calculated directly: the orientation test can be used[how?].)
- ( can be performed in time[how?].)
- (Note: at the iteration , and is known and is a point in the convex hull of :
- in this case, it is the point of with the lowest y coordinate.)
- (Choose the point which maximizes the angle [why?] to be the next point on the convex hull of .)
- (Jarvis march terminates when the next selected point on the convext hull, , is the initial point, .)
- if
- (Return the convex hull of which contains points.)
- (Note: of course, no need to return which is equal to .)
- return
- else
- (If after iterations a point has not been found so that , then .)
- (We need to start over with a higher value for .)
Implementation[]
Chan's paper contains several suggestions that may improve the practical performance of the algorithm, for example:
- When computing the convex hulls of the subsets, eliminate the points that are not in the convex hull from consideration in subsequent executions.
- The convex hulls of larger point sets can be obtained by merging previously calculated convex hulls, instead of recomputing from scratch.
- With the above idea, the dominant cost of algorithm lies in the pre-processing, i.e., the computation of the convex hulls of the groups. To reduce this cost, we may consider reusing hulls computed from the previous iteration and merging them as the group size is increased.
Extensions[]
Chan's paper contains some other problems whose known algorithms can be made optimal output sensitive using his technique, for example:
- Computing the lower envelope of a set of line segments, which is defined as the lower boundary of the unbounded trapezoid of formed by the intersections.
- Hershberger[5] gave an algorithm which can be sped up to , where h is the number of edges in the envelope
- Constructing output sensitive algorithms for higher dimensional convex hulls. With the use of grouping points and using efficient data structures, complexity can be achieved provided h is of polynomial order in .
See also[]
References[]
- ^ a b Timothy M. Chan. "Optimal output-sensitive convex hull algorithms in two and three dimensions". Discrete and Computational Geometry, Vol. 16, pp.361–368. 1996.
- ^ Frank Nielsen. "Grouping and Querying: A Paradigm to Get Output-Sensitive Algorithms". Discrete and Computational Geometry, LNCS 1763, pp. 250–257, 2000.
- ^ Frank Nielsen. "Adaptive Computational Geometry". Ph.D. thesis, INRIA, 1996.
- ^ B. Chazelle Jiří Matoušek. "Derandomizing an output-sensitive convex hull algorithm in three dimensions". Computational Geometry, Vol. 5, pp.27–32. 1995.
- ^ J. Hershberger. "Finding the upper envelope of n line segments in O(n log n) time". Information Processing Letters , Vol. 33, pp.169–174. 1989.
- Convex hull algorithms