Effective Construction of Convex Hull Algorithms

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

2017 19th International Symposium on Symbolic and Numeric Algorithms for Scientific Computing (SYNASC)

Effective construction of convex hull algorithms

P. Mitura, I. Šimeček, I. Kotenkov


Department of Computer Systems, Faculty of Information Technology,
Czech Technical University in Prague, Prague, Czech Republic Email: miturpet,xsimecek,koteniv1@fit.cvut.cz

Abstract—Finding the convex hull of a set of points in last two vertices, we have O RIENT(vn−1 , vn , v1 ) ≤ 0 and
a plane is one of the most common problems in computa- O RIENT(vn , v1 , v2 ) ≤ 0.
tional geometry. We survey known algorithms for solving this
problem and look into methods of their effective and parallel As we are going to focus on time performance of known
implementation. A simple generator of random input datasets algorithms, the first thing we are concerned with is their
is created, with an option to control the number of points asymptotic time complexity. It has been shown, that in case
on the resulting hull. We implement all surveyed algorithms
along with their optimizations and compare them using our the output is ordered in counterclockwise (or clockwise)
generator. Our measurements show, that Quickhull algorithm order, the best asymptotic lower bound for time complexity
using optimizations proposed by Hoang and Linh [1] has the of finding the convex hull of n points in the Euclidean plane
best performance among the implemented methods and is is Ω(n log n) [3, pp. 33–37].
faster than the current state of the art libraries. It is also important to note that if we take output sensitivity
Keywords-computational geometry, convex hull, Quickhull, into account, there are algorithms which can solve this
parallel processing, OpenMP problem in O(n log h), where h is the number of points
on resulting hull [4] [5].
I. I NTRODUCTION
II. K NOWN SOLUTIONS
The convex hull of a set of points S is defined as the
We have selected 5 algorithms for comparison and imple-
smallest convex set containing all points in S. In this paper,
mentation, representing different existing approaches to the
we limit ourselves to finding the convex hull of points in a
problem. Short description of each algorithm follows, along
plane, which is the most common version of this problem.
with the reason why we decided to include it. In all following
It is known that convex hull is a polygon, with all of its
algorithms analysis, we will presume we were given a set
vertices being elements of the input set S [2]. We denote
V = {v1 , v2 , . . . , vn } of n points in R2 as an input, and the
the number of points in S as n and the number of points on
size of resulting convex hull for this set is h.
the resulting hull as h.
Throughout this paper, we will represent convex hulls as A. Compared algorithms
a list of their vertices, sorted in counterclockwise order as Jarvis Scan: Also known as the gift wrapping algorithm,
they appear on the perimeter. This prompts us to define Jarvis Scan is one of the most straightforward solutions to
orientation of three points: the convex hull problem. It was presented by Jarvis in 1973
Definition 1. ([2, pp. 11–12]) For a given triplet of points [6] and is a specialization and simplification of earlier work
{a, b, c} ∈ R2 with coordinates (ax , ay ), (bx , by ), (cx , cy ), by Chand and Kapur in 1970 [7].
we define operation O RIENT(a, b, c) as: Its basic principle is to start with a point that is guaranteed
  to appear on the hull (which for example applies to the point
ax ay 1 with smallest y coordinate, selecting the one with greater x
 
O RIENT(a, b, c) =  bx by 1 coordinate in case of ties). We will denote this point p1 and
 cx cy 1 proceed by finding the next point on hull p2 , such that for
each point v ∈ V \{p1 , p2 }, we have O RIENT(p1 , p2 , v) ≤ 0.
furthermore, we will call the triplet {a, b, c}: This process can be then repeated for finding the pi+1 using
• counterclockwise, if O RIENT (a, b, c) < 0 pi , until we find p1 again as the next point, which means
• clockwise, if O RIENT (a, b, c) > 0 we have found the convex hull {p1 , . . . , ph }.
• collinear, if O RIENT (a, b, c) = 0 Searching for the next point can be done in O(n) time
in several ways (which will be further discussed in Section
Which leads to a more formal definition of counterclock-
III), leading to overall time complexity of O(nh). In most
wise ordering:
cases, this is worse than using an algorithm which runs in
Definition 2. We call a list of vertices V = {v1 , . . . , vn } O(n log n) or better, but it is important to note that the
sorted in counterclockwise order, if for each i ≤ n − 2 simplicity of this approach means it will have relatively
we have O RIENT(vi , vi+1 , vi+2 ) ≤ 0 and specifically for small complexity constants and could be easily parallelized.

978-1-5386-2626-9/17/31.00 ©2017 IEEE 105


DOI 10.1109/SYNASC.2017.00028

Authorized licensed use limited to: Monash University. Downloaded on October 06,2022 at 09:44:32 UTC from IEEE Xplore. Restrictions apply.
Graham Scan and Andrew’s algorithm: Graham Scan is found by recursive calls are put on the hull between points
an algorithm shown by Graham in 1972 [8], being able to a, c and c, b respectively.
solve the convex hull problem in O(n log n) time. Time complexity of this algorithm can be formulated
As in Jarvis Scan, it starts by finding the initial point p1 recursively as T (n) = T (n − x) + T (x) + O(n), with
on the convex hull using the same criteria. Then, it sorts all 0 ≤ x ≤ n. Analogously to Quicksort analysis, T (n) equals
points in V \ {p1 } in ascending order by their polar angle O(n2 ) if x = 0 in every instance, but it can be shown that
with respect to p1 as the coordinate center. Finally, it iterates in case of uniformly random choice of x from range [0, n],
over the sorted points starting with the point that has the the expected value of T (n) is only O(n log n).
smallest polar angle, which is guaranteed to follow p1 on Furthermore, the worst case scenario would have to rely
the perimeter, so we can denote it p2 . on repeatedly dividing coordinates of initial points on the
During all remaining iterations, it will consider the ori- hull by some costant factor. In case of implementation
entation of points ph−1 , ph , x, where h is the number using some form of finite precision floating point arithmetic,
of points found on hull so far (initially set to h = 2 this would be practically unrepresentable for large input
after adding p2 ) and x is the currently considered point. data sets. Unlike Quicksort, Quickhull also achieves some
If triplet {ph−1 , ph , x} is clockwise, it repeatedly removes speedup by deleting unusable points from triangle abc,
the last found point ph and decreases h by one until which means it could even approach linear runtime in certain
O RIENT(ph−1 , ph , x) ≤ 0 is satisfied. Then, it increases h cases (like diamond shaped dataset).
by one and sets ph = x. Chan’s algorithm: Named by its author, Chan’s algorithm
The time complexity of this algorithm is dominated by was presented by Chan in 1996 [5] and it falls into the class
sorting the points, which takes O(n log n) time. The iterative of algorithms for convex hull problem, which could solve it
phase can only manipulate with each point in V twice, in better time than O(n log n) by being output sensitive, in
adding or removing it from the partial hull. That means this case having the overall time complexity of O(n log h).
it takes only O(n) time and the overall complexity is The basic principle of this algorithm lies in guessing
O(n log n), making it asymptotically worse than output- the number of points h lying on resulting convex hull,
sensitive algorithms, but with fairly small constant factors. which allows us to split the input set into n/h  disjoint
There is also an algorithm shown by Andrew in 1979 subsets of size at most h and find the convex hull of each
[9], that resembles Graham Scan with key difference in sort of these subsets using one of the conventional O(n log n)
order: Andrew’s algorithm sorts points by their x coordinate, algorithms. Using these partial hulls, we can find the overall
then proceeds with similar iterative phase, but does it twice hull using similar approach as we have seen in Jarvis Scan,
for upper and bottom half of the hull. but considering only one point per partition, found by binary
The complexity of this algorithm is obviously the same search over its convex hull.
and we also expect its performance to be very similar to
Graham Scan. B. Unused solutions
Quickhull: This algorithm was presented in 1996 by There are numerous approaches that were left off from
Barber, Dobkin and Huhdanpaa [10]. Its name yields to the this comparison. Various preprocessing heuristics are being
fact that its time complexity analysis closely resembles the used, the most common is known as the Akl-Toussaint
one of Quicksort, and it also runs in O(n log n) time on heuristic [11], which is based on pruning points outside
average, and O(n2 ) in worst case. the quadrilateral formed by extremal points. However, these
It is based on the idea, that if we take two points a, b lying techniques almost always depend on the shape or some
on the convex hull, and one of the halfplanes defined by line other property of input point set, making their performance
ab, then the point c on this halfplane that is farthest from entirely dependend on chosen testing methodology.
ab also lies on the hull. Once again, initial points a, b can Another possibility is the use of approximation algorithm,
be found as points with the mimimum and the maximum the most famous of them being the BFP Approximation [12].
coordinate on x axis. These allow solving the convex hull problem in linear time,
This means we first divide the points in V into two with fixed constraints on the margin of error in area of the
halfplanes defined by ab, and process each one separately. resulting hull.
For each partition, we find the point c farthest from ab,
C. Existing implementations
add it to the hull and then discard all points inside the
triangle abc. Remaining points are divided to two groups, We have selected three commonly used implementations
one that lies on the halfplane defined by line ac, that does of convex hull finding algorithms for comparison:
not intersect with abc except for the segment ac, and the • Qhull [13] computes the convex hull using Quickhull,
rest is assigned to the group above the cb line. For both is written by the original authors of this algorithm.
of these groups and their corresponding lines, we proceed Provides a wide range of other tools, such as Delaunay
recursively using the same logics as with the ab line. Points triangulation and Voronoi diagram.

106

Authorized licensed use limited to: Monash University. Downloaded on October 06,2022 at 09:44:32 UTC from IEEE Xplore. Restrictions apply.
• CGAL [14] is a collection of computational geometry the cotangent of their polar angles, which is monotonic on
algorithms, presenting its users with a choice of five the given interval and computable only using floating point
different algorithms for computing the planar convex division (as opposed to computing inverse tangent to get
hull. exact angles).
• Boost [15] is a widely used C++ library, containing These optimizations allow Graham Scan to catch up
numerous solutions for common problems. Includes to Andrew’s algorithm in terms of performace, detailed
a convex_hull function for computing 2D convex comparison would be done later on in Section V.
hulls.
C. Quickhull
III. S EQUENTIAL OPTIMIZATIONS In case of Quickhull optimizations, our main source was
All algorithms were implemented in the C++ program- the “Quicker than Quickhull” paper published in 2015 [1].
ming language. Besides automatic compiler optimizations, Authors of this work present several modifications to this
we survey or propose series of improvements targeted at algorithm, claiming their version is three times faster than
reducing hidden constants in algorithm runtimes. These the naive implementation.
mainly include reductions in number of trigonometric func- The first trick presented in [1] reduces the number of
tions, and reuse of previously computed results for other operations needed to find orientation of three points. By
purposes. default, the O RIENT function requires at least seven real
number instructions:
A. Jarvis Scan
O RIENT(a, b, c) = (ax − bx )(by − cy ) − (ay − by )(bx − cx )
Beginning with the Jarvis Scan algorithm, we can observe
that the dominant operation in terms of runtime is finding The key observation here is that every time Quickhull
the next point on the hull pi+1 , such that no other point lies iterates over the set of points in some partition, it only
on the right of line segment pi pi+1 . This could be naively changes the third point c in the computation, points a and b
done by computing the polar angles of all points (assuming are fixed. This allows us to precompute parts of the formula
we shift the coordinate center to pi ), and use the line pi pi−1 by transforming it to the following form:
as our x axis (we choose the original x axis for i = 1). With
all of these conditions satisfied, point pi+1 is the one with cy (bx − ax ) + cx (ay − by ) + bx (by − ay ) + by (ax − bx )
the minimum polar angle in V \ {pi }. and then expressing it as
However, this approach demands use of expensive
trigonometric operation such as the arctangent in order to α = ay − by β = a x − bx γ = βby − αbx
compute these angles, typically costing hundreds of CPU O RIENT(a, b, c) = αcx − βcy + γ
cycles. This could be reduced by chosing any point as the
initial candidate pi+1 and iterating over all remaining points where α β and γ are evaluated before the cycle, and all
v ∈ V \ {pi , pi+1 }. For each of them, we find out whether orientations computed while iterating over each possible
the points pi , pi+1 and v make clockwise turn, and if they point c only use the reduced formula, utilizing only four
do, v is assigned as the new pi+1 . floating point instructions.
Another modification proposed by [1] takes advantage of
B. Graham Scan the fact that finding the farthest point from line segment ab
Graham Scan also uses trigonometric operations to sort in current partition can be done by computing cross product
points in the input set by their polar angle, and it could  and bc
of ab  (denoted by ab  × bc)
 for each considered point
be optimized in a similar way by comparing orientations of c. Cross product gives us the area of parallelogram with
points. That still means we have to compute cross product the vectors for sides and this area could be also expressed
in each comparison, which costs us several floating point as distance between a and b (which is fixed) multiplied by
operations in a section that dominates the time complexity. distance from line segment ab to the point c. That means the
We propose to further improve the point sorting phase point c with the maximal value |ab × bc|
 is also the farthest
by precomupting the polar angle of each point This means from ab.
the number of expensive floating point operations related to It also stands that ab  × bc
 is equal to the value of
angle computations would be reduced to O(n) and all of O RIENT(a, b, c), which is already computed while partition-
the O(n log n) comparisons in sorting algorithm could be ing points to recursive instances, before the farthest point
implemented only by comparing two precomputed values. is needed. This means we could only store the point with
It can also be observed that all points in V \ {p1 } have maximal O RIENT value in each partition, and send it to the
their polar angle in the range [0, π) (we use p1 as an origin corresponding recursive instance as the farthest point.
of coordinate system, and it has the lowest y coordinate of Third improvement is taken from Section 4.2 of [1], its
all points in V ). Thus we can limit ourselves to comparing basic idea is to limit the maximum count of orientation calls

107

Authorized licensed use limited to: Monash University. Downloaded on October 06,2022 at 09:44:32 UTC from IEEE Xplore. Restrictions apply.
while partitioning points from two to one. Assuming the would be only used if the simple quadrant splitting does not
point a has smalled x coordinate than b, a point could only utilize all processing units.
be placed in the part above the ac segment if its x coordinate
is smaller than the one of c, an only above the cb segment B. Graham Scan
otherwise. The case of a having higher x coordinate than b As the time complexity of both Graham Scan and An-
is similar. drew’s algorithm is dominated by sorting the input point
set, and parallelization of sorting is very common task, we
D. Chan’s algorithm
decided to use the parallel extension of the GNU C++ library
Regarding the Chan’s algorithm, the main optimization [17] for this purpose. More specifically, we have used the
point is the choice of algorithm for finding partial convex __gnu_parallel::sort function in both algorithms.
hulls. All of the algorithms mentioned above are applicable, Parallelization of linear parts of these algorithms was also
with the possibility of using different algorithms for partial considered, finding the upper and lower hull in Andrew’s
hulls based on their size. We will base the choice of algo- algorithm in two threads being the obvious candidate. How-
rithms on their measured performance, especially on small ever, there are few opportunities beyond that, as paralleliza-
input set sizes. This will be further discussed in Section V. tion of incremental pass at the end of both algorithms would
be complicated at best, and speeding up the linear parts
IV. PARALLELIZATION
would not have large impact on overall runtime anyway.
Along with sequential optimizations, we have explored
and implemented methods of parallelization for all surveyed C. Quickhull
algorithms. All parallel programming is done under shared Quickhull is a typical example of divide and conquer
memory model, using the OpenMP [16] library. algorithm, and task parallelism is used in majority of such
A. Jarvis Scan cases. Every time the algorithm recursively branches into
two subproblems, each partition is saved into shared task
In case of Jarvis Scan, there are two general ways of pool, and assigned a thread to do its work as soon as there is
parallelization to be considered. First we can observe, that a free one. In order to prevent overcrowding of the task pool
the algorithm can be started from up to four distinct points, with small problem instances and consequentively increasing
as any extremal point on both x and y axis is guaranteed the overhead, a sequential of algorithm version is used for
to lie on the convex hull. As computations between these subproblems below certain size.
points could run independently, we can split the algorithm
into four parallel sections, each of them operating until it D. Chan’s algorithm
finds the next extremal point. This is an easy solution with
Chan’s algorithm also allows some degree of paralleliza-
minimal overhead, but it does not scale beyond 4 threads
tion. Finding partial hulls in the first step can be done
and is highly dependent on the distribution of the points on
independently for each of the hulls, which means it could
the hull.
be easily divided between threads. Using parallel versions of
We can also observe, that an extremal point could be
convex hull algoritms for subhulls may be also considered,
found in an arbitrary direction, making it possible to extend
although it would presumably cause larger overhead and
this approach to any number of threads. However, this
possibly poor balancing.
technique is meant to provide an alternative with lower
Combining partial hulls could be parallelized as well,
overhead than the second option discussed below. Adding
in the same manner as we have seen in the Jarvis March
a linear number of non-trivial distance checks per thread
algorithm.
may negatively affect the performance of the algorithm, and
considering that values of h where Jarvis Scan is worth V. M EASUREMENTS
running are usually low, the dependence on distribution of
points on the hull would also increase significantly. Because All measurements have been performed on a server with
of this, we have decided to use the simpler 4 threads version. following configuration:
The second option is to parallelize the search for the next • 2 × CPU Intel Xeon Processor E5-2620 v2 (15MB L3
point on convex hull, by splitting the input set uniformly cache per CPU),
among threads and finding one candidate point for each • CPU cores: 6 per CPU, 12 in total,
partition. Candidate points are them scanned sequentially. • Memory size: 32 GB RAM, total max. memory band-
This approach ensures good load balancing and scales well width: 51.2 GB/s,
into any number of threads, but also comes with slightly • Peak single precision floating point performance 0.48
higher overhead. Tflops (using base clocks),
It is also possible to use both of these methods at • OS Linux, C++ compiler (g++) version 5.4.0 with
once, ensuring the more expensive inner cycle parallelization switches -O3 -march=native -mavx -fopenmp.

108

Authorized licensed use limited to: Monash University. Downloaded on October 06,2022 at 09:44:32 UTC from IEEE Xplore. Restrictions apply.
JSPA QHN
15 JSO QHPC
4 QHFAR
Time [s]

Time [s]
QHALL
10

2
5

0 0
1 · 106 2 · 106 3 · 106 4 · 106 1 · 107 2 · 107
Input point set size Input point set size

Figure 1. Jarvis Scan version comparison Figure 3. Quickhull version comparison

GSPA CAGS
GSO
10 CAQH
GSPRE 10 CACOMB
Time [s]

AA

Time [s]
5 5

0 0
1 · 106 3 · 106 5 · 106 1.5 · 106 3 · 106 4.5 · 106 6 · 106
Input point set size Input point set size

Figure 2. Graham Scan version comparison Figure 4. Chan’s algorithm version comparison

Utilization of cores for testing parallel speedup has been polygon and time performance of tested algorithms. Tests
limited by omp_set_num_threads() function, wall with variable input set size have fixed size of output convex
clock times have been measured by omp_get_wtime(). hull, with 50 points being the default value (unless stated
A. Methods of testing otherwise).
Jarvis Scan: In Section III-A, we have described the
Since runtime of at least Jarvis Scan and Chan’s algorithm
common trick of using orientation checks (we will denote
is directly dependent on number of points on resulting
this version as JSO) instead of finding the polar angles
convex hull, we have designed a generator of input sets that
(denoted JSPA). The speedup achieved thanks to this change
has control over this parameter. More speciffically, it can
is documented in Figure 1.
generate random sets of points that are uniformly distributed
Graham Scan: Regarding Graham Scan, in Section III-B,
inside of regular or irregular convex polygons with given
we have proposed to speed up comparisons in point sorting
number of vertices. As these vertices are also parts of the
by precomputing the cosine of each point (version GSPRE).
input set, the number of points on convex hull is guaranteed
Speed comparison with polar angle based (GSPA) and
to be equal to their count, which means we can observe
dependency on this parameter in addition to the size of
the input set and number of cores. An example of dataset
generared inside a regular and irregular hexagon is shown
on Figure 5.
B. Sequential results
Before we mutually compare the optimized implementa-
tions of algorithms, the effect of individual improvements
is tested. This allows us to assess whether the change was
successful, and how significantly has it reduced the runtime.
All tests were conducted on regular polygons, since we
haven’t found any connection between the shape of the Figure 5. Example of generated regular and irregular hexagonal point set.

109

Authorized licensed use limited to: Monash University. Downloaded on October 06,2022 at 09:44:32 UTC from IEEE Xplore. Restrictions apply.
30
Jarvis March
Graham Scan
Quickhull
Chan
20
Time [s]

10

0
1 2 4 8 12 16 24
Number of threads

Figure 6. Comparison of parallel implementation runtimes.

naive version started to show up, although both algorithms


exhibited significant slowdown. Version with added farthest
15
GSO point precomputation (QHFAR) is more than two times
Time [s]

QHFAR faster than the naive implementation. Variant that cuts some
10 CACOMB orientation computations based on coordinates (QHALL) on
the top of improvements in QHFAR is slightly slower than
5 the version without this change, presumably due to needed
comparisons being more time consuming than an occasional
0 extra orientation check.
250 500 750 1,000
Chan’s algorithm: For Chan’s algorithm, we have com-
Output convex hull size
pared results of Jarvis Scan, Graham Scan and Quickhull on
small hull sizes. They have shown Quickhull passes Graham
Figure 7. Comparison of sequential implementations, 107 input points.
scan in terms of speed at approximately 500 points in the
input set, with Jarvis Scan being the slowest for practially
all cases. We have implemented three variants, using solely
orientation comparison based (GSO) version is shown in Graham Scan (CAGS), Quickhull (CAQH) and one that
Figure 2. We can see that both GSPRE and GSO variants switches from Graham Scan to Quickhull on point sets
are visibly faster than the naive GSPA implementation, with larger than 500 points (CACOMB). Tests in Figure 4 were
the GSPRE being even faster than the common orientation conducted with increased output hull size of 1000 points
version. Furthermore, we have compared the Andrew’s al- in order to cover the effects of these improvements. We
gorithm implementation (AA), which exhibits slightly worse can observe that the performance of CACOMB is slightly
performance than improved Graham Scan. Since the time improved in comparison with other versions.
complexity of both algorithms is dominated by sorting, it
means the linear precomputation step in Graham Scan runs Finally, we have compared all implemented algorithms
faster than the extra linear pass in Andrew’s algorithm. together. Measurements with respect to input set size are
Quickhull: In Quickhull, we have tested effects of three visualised in Figure 8, using fixed output convex hull size of
improvements taken from [1] described in Section III-C 100 points. Results with varying output convex hull size are
and compared them with the results provided in the source shown on Figure 7, conducted on input sets with 107 points
article. Our results are visualised in Figure 3. Partial cross (Jarvis Scan excluded). Both tests show that Quickhull is
product precumputing (QHPC) does not exhibit significant significantly faster than all other options. Chan’s algorithm,
improvements over naive implementation (QHN), which is despite its output sensitivity, is slower than Quickhull on
different than conclusions in [1]. The reason for this might every convex hull size, probably because of its large hidden
be in the version and flags of the used compiler, which have constants in time complexity.
not been stated in the source paper. After compiling our code Dependence on the output size of Jarvis Scan is not
without the -O3 flag, improvements in comparison with the visualized, since its runtimes are too high for the scale. It

110

Authorized licensed use limited to: Monash University. Downloaded on October 06,2022 at 09:44:32 UTC from IEEE Xplore. Restrictions apply.
Qhull and CGAL libraries using Quickhull (CGAL provides
JSO
a total of five algorithms for the problem, Quickhull always
10 GSPRE
QHFAR
performed the best of them), and the Boost library utilizing
Graham Scan. As all of the state of the art libraries use
Time [s]

CACOMB
sequential algorithms, our implementation also runs in its
5 single thread version.
Results are shown in Figure 9, our implementation has
more than 2 times shorter runtimes than the second best
tested implementation from the CGAL library. Closer in-
0
2 · 106 4 · 106 6 · 106 8 · 106 spection of these libraries’ source code shows, that Qhull
Input point set size uses more general version of the algorithm scalable to
three dimensions, which may have affected its performance.
Figure 8. Comparison of sequential optimized implementations, h = 100. CGAL, however, uses fairly straightforward implementation
of Quickhull, and its slower runtimes could likely be at-
tributed to the lack of optimizations.
is faster than Graham Scan for up to 50 points on hull and
does not surpass Quickhull even on the smallest hull sizes. VI. C ONCLUSION
Quickhull also exhibits some amount of dependence on We have studied and implemented improvements for five
output hull size, even though it is not enough to be slower commonly used planar convex hull algorithms. Results of
than Graham Scan. It has to be noted it is not possible to our measurements show that even naive implementation
consider much larger output hull sizes with the current im- of Quickhull is faster than any other tested algorithm in
plementation, as 64 bit floating point number representation most tested cases. This is mainly caused by its ability to
is used for point coordinates, causing the triplets of points prune points in the process, which significantly reduces time
on the hull to be considered collinear after passing certain complexity constants. As we have mentioned in Section
amount. II, the only input sets where pruning is not possible, or
Quickhull reaches its quadratic upper bound, require all
C. Parallel results
points in the input set to lie on the convex hull. Dataset like
Our parallel implementations of surveyed algorithms have that is practically unrepresentable using a finite precision
been compared in terms of runtime on input with 1.5 · 107 arithmetics for n larger than several tens of thousands.
points, 300 of them lying on the convex hull. All considered, the only cases where we recommend to
Sequential improvements from Section III are used as consider algorithms other than Quickhull are large batches
a base for all parallelized algorithms. Figure 6 displays of very small datasets, and inputs with extreme numbers of
algorithm runtimes depending on number of cores used. points on the hull are expected, possibly combined with high
Parallel speedups for the same data are visualized in Figure or arbitrary precision arithmetics.
10. Moreover, we have found out that the sequential optimiza-
Experiments have shown that the best way of parallelizing tions by [1] can reduce runtime of Quickhull to less than
Jarvis Scan uses the combination of both methods described half of its original values. Our optimized implementation
in Section IV-A. Figure 10 shows that significant speedup is more than two times faster than any algorithm used
is only achieved with up to four threads, which is under- in CGAL and four times faster than Qhull, making it an
standable in case of first method, and possibly caused by interesting candidate for future uses in time performace
increasing overhead in the second described method. focused applications.
The lower bound for using parallel task for a Quickhull In terms of parallelization, Quickhull has failed to match
subproblem was set to 10 000 points. Results in Figure 6 the speedup of much simpler solutions used in other al-
show that while Quickhull has the worst speedup of all tested gorithms. Additional tests observing the number of points
algorithms, its runtime still beats any other variant, even if processed by each core suggest, that this is not just an
all 12 cores of our setup were utilized. issue of uneven work distribution. The overhead of a task
Chan’s algorithm is using sequential versions of convex pool based parallel solution seems to be too large for an
hull algorithms for computing subhulls, as use of parallel algorithm with so short sequential runtimes. Despite these
ones only caused mild slowdown. shortcomings, Quickhull was still the best performer at any
D. Comparison with state of the art libraries tested number of threads.
We have compared the most widely used implementations ACKNOWLEDGEMENT
for solving the planar convex hulls with our best performing
This research has been supported by CTU internal grant
implementation, being the QHFAR variant of Quickhull.
SGS17/215/OHK3/3T/18.
Namely, we have tested the performance of solvers from

111

Authorized licensed use limited to: Monash University. Downloaded on October 06,2022 at 09:44:32 UTC from IEEE Xplore. Restrictions apply.
2 Our implementation
Boost
CGAL
Qhull
1.5
Time [s]

0.5

0
2 · 106 4 · 106 6 · 106 8 · 106
Input point set size

Figure 9. Comparison of our implementation with state of the art libraries, h = 100.

4 [7] D. R. Chand and S. S. Kapur, “An algorithm for convex


polytopes,” Journal of the ACM, vol. 17, no. 1, pp. 78–86,
1970.
3
Speedup

[8] R. L. Graham, “An efficient algorithm for determining the


2 convex hull of a finite planar set,” Inf. Process. Lett., vol. 1,
no. 4, pp. 132–133, 1972.
1
[9] A. Andrew, “Another efficient algorithm for convex hulls
Jarvis Graham Quickhull Chan
in two dimensions,” Information Processing Letters, vol. 9,
0 no. 5, pp. 216–219, 1979.
1 4 8 16 24
Number of threads [10] C. B. Barber, D. P. Dobkin, and H. Huhdanpaa, “The
quickhull algorithm for convex hulls,” ACM Transactions on
Figure 10. Comparison of parallel speedups. Mathematical Software, vol. 22, no. 4, pp. 469–483, 1996.

[11] S. G. Akl and G. T. Toussaint, “A fast convex hull algorithm,”


R EFERENCES Information Processing Letters, vol. 7, no. 5, pp. 219 – 222,
1978.
[1] N.-D. Hoang and N. K. Linh, “Quicker than quickhull,”
Vietnam Journal of Mathematics, vol. 43, no. 1, pp. 57–70, [12] J. L. Bentley, F. P. Preparata, and M. G. Faust, “Approxima-
2015. tion algorithms for convex hulls,” Commun. ACM, vol. 25,
no. 1, pp. 64–68, 1982.
[2] S. Ramaswami, “Convex hulls: Complexity and applications
(a survey),” 1993. [Online]. Available: http://repository.upenn. [13] C. B. Barber and H. Huhdanpaa, “Qhull 2015.2.” [Online].
edu/cgi/viewcontent.cgi?article=1272&context=cis reports. Available: http://www.qhull.org/.

[3] J. G. Erickson, “Lower bounds for fundamental geometric [14] CGAL Editorial Board, “Cgal 4.8.” [Online]. Available: http:
problems,” tech. rep., 5th Annual European Symposium on //www.cgal.org/”.
Algorithms (ESA’97), 1996.
[15] Boost Development Team, “Boost c++ libraries 1.55.0.” [On-
[4] D. G. Kirkpatrick and R. Seidel, “The ultimate planar convex line]. Available: http://www.boost.org/users/history/version
hull algorithm?,” SIAM Journal on Computing, vol. 15, no. 1, 1 55 0.html.
pp. 287–299, 1986.
[16] “OpenMP API for parallel programming, version 4.0.” [On-
[5] T. M. Chan, “Optimal output-sensitive convex hull algorithms line]. Available: http://www.openmp.org/wp-content/uploads/
in two and three dimensions,” Discrete & Computational OpenMP4.0.0.pdf.
Geometry, vol. 16, no. 4, pp. 361–368, 1996.
[17] “The GNU C++ library documentation, parallel mode.”
[6] R. Jarvis, “On the identification of the convex hull of a finite [Online]. Available: https://gcc.gnu.org/onlinedocs/libstdc++/
set of points in the plane,” Information Processing Letters, manual/parallel mode.html.
vol. 2, no. 1, pp. 18–21, 1973.

112

Authorized licensed use limited to: Monash University. Downloaded on October 06,2022 at 09:44:32 UTC from IEEE Xplore. Restrictions apply.

You might also like