Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos...

33
Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013

Transcript of Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos...

Page 1: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

Computational Geometry:Convex hull II

Panos Giannopoulos, Wolfgang Mulzer, Lena SchlipfAG TI

SS 2013

Page 2: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

Outline

Graham’s scan (Andrew’s variant)

Chan’s algorithm

Assignment 2

,FU Berlin, Computational Geometry:, SS 2013 2

Page 3: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

Convex hull

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Convex hull

For any subset of the plane (set ofpoints, rectangle, simple polygon),its convex hull is the smallest convexset that contains that subset

Computational Geometry Lecture 1: Introduction and Convex HullsCGAL Demo

Anybody wants programming exercises ?

,FU Berlin, Computational Geometry:, SS 2013 3

Page 4: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

Convex hull problem

Give an algorithm that computesthe convex hull of any given setof n points in the plane efficiently

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Convex hull problem

Give an algorithm that computes theconvex hull of any given set of npoints in the plane efficiently

The input has 2n coordinates, soO(n) size

Question: Why can’t we expect todo any better than O(n) time?

Computational Geometry Lecture 1: Introduction and Convex Hulls

Lower bound: Any convex hull algorithm requires Ω(n logn)operations in the quadratic decision treemodel [Yao, 1981]

,FU Berlin, Computational Geometry:, SS 2013 4

Page 5: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

Graham’s scan (Andrew’s variant)

Approach: incremental, from left to right

First compute the upper boundary (hull) of the convex hull thisway (property: on the upper hull, points appear in x-order)

Main idea: sort the points from left to right (= by x-coordinate)Then, insert the points in this order, and maintain the upper hullso far

Then, compute the lower hull analogously (from right to left)

Finally, append lower hull to upper hull

,FU Berlin, Computational Geometry:, SS 2013 5

Page 6: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

The idea...

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

Observation: from left toright, there are only right turnson the upper hull

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 6

Page 7: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

The idea...

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

Initialize by inserting theleftmost two points

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 6

Page 8: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

The idea...

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

If we add the third point therewill be a right turn at theprevious point, so we add it

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 6

Page 9: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

The idea...

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

If we add the fourth point weget a left turn at the thirdpoint

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 6

Page 10: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

The idea...

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

. . . so we remove the thirdpoint from the upper hullwhen we add the fourth

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 6

Page 11: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

The idea...

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

If we add the fifth point we geta left turn at the fourth point

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 6

Page 12: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

The idea...

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

. . . so we remove the fourthpoint when we add the fifth

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 6

Page 13: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

The idea...

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

If we add the sixth point weget a right turn at the fifthpoint, so we just add it

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 6

Page 14: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

The idea...

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

We also just add the seventhpoint

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 6

Page 15: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

The idea...

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

When adding the eight point. . . we must remove theseventh point

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 6

Page 16: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

The idea...

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

. . . we must remove theseventh point

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 6

Page 17: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

The idea...

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

. . . and also the sixth point

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 6

Page 18: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

The idea...

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

. . . and also the fifth point

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 6

Page 19: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

The idea...

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

After two more steps we get:

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 6

Page 20: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

The algorithm (for the upper hull..)

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

The pseudo-code

Algorithm ConvexHull(P)Input. A set P of points in the plane.Output. A list containing the vertices of CH(P) in clockwise order.1. Sort the points by x-coordinate, resulting in a sequence

p1, . . . ,pn.2. Put the points p1 and p2 in a list Lupper, with p1 as the first

point.3. for i← 3 to n4. do Append pi to Lupper.5. while Lupper contains more than two points and the

last three points in Lupper do notmake a right turn

6. do Delete the middle of the last three points fromLupper.

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 7

Page 21: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

..and for the lower hull..

7. Put the points pn and pn−1 in a list Llower, with pn as the firstpoint.

8. for i← n− 2 down to 19. do Append pi to Llower.

10. while Llower contains more than 2 points and the lastthree points in Llower do not make a right turn

11. do Delete the middle of the last three points from Llower

12. Remove the first and last point from Llower to avoidduplication of the points where the upper and lower hull meet.

13. Append Llower to Lupper, and call the resulting list L.14. return L

,FU Berlin, Computational Geometry:, SS 2013 8

Page 22: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

..and for the lower hull.

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

The pseudo-code

Then we do the same for thelower convex hull, from rightto left

We remove the first and lastpoints of the lower convex hull

. . . and concatenate the twolists into one

p1, p2, p10, p13, p14

p14, p12, p8, p4, p1

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 9

Page 23: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

Algorithm analysis

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Algorithm analysis

Algorithm analysis generally has two components:

proof of correctness

efficiency analysis, proof of running time

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 10

Page 24: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

Correctness

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Correctness

Are the general observations on which the algorithm is basedcorrect?

Does the algorithm handle degenerate cases correctly?

Here:

Does the sorted order matter if two or more points have thesame x-coordinate?

What happens if there are three or more collinear points, inparticular on the convex hull?

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 11

Page 25: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

Running time

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Efficiency

Identify of each line of pseudo-code how much time it takes, if it isexecuted once (note: operations on a constant number ofconstant-size objects take constant time)

Consider the loop-structure and examine how often each line ofpseudo-code is executed

Sometimes there are global arguments why an algorithm is moreefficient than it seems, at first

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 12

Page 26: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

Running time

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

The pseudo-code

Algorithm ConvexHull(P)Input. A set P of points in the plane.Output. A list containing the vertices of CH(P) in clockwise order.1. Sort the points by x-coordinate, resulting in a sequence

p1, . . . ,pn.2. Put the points p1 and p2 in a list Lupper, with p1 as the first

point.3. for i← 3 to n4. do Append pi to Lupper.5. while Lupper contains more than two points and the

last three points in Lupper do notmake a right turn

6. do Delete the middle of the last three points fromLupper.

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 12

Page 27: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

Running time

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Efficiency

The sorting step takes O(n logn) time

Adding a point takes O(1) time for the adding-part. Removingpoints takes constant time for each removed point. If due to anaddition, k points are removed, the step takes O(1+ k) time

Total time:

O(n logn)+n

∑i=3

O(1+ ki)

if ki points are removed when adding pi

Since ki = O(n), we get

O(n logn)+n

∑i=3

O(n) = O(n2)

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 12

Page 28: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

Running time

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Efficiency

Global argument: each point can be removed only once from theupper hull

This gives us the fact:

n

∑i=3

ki ≤ n

Hence,

O(n logn)+n

∑i=3

O(1+ ki) = O(n logn)+O(n) = O(n logn)

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 12

Page 29: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

Theorem

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Final result

The convex hull of a set of n points in the plane can be computedin O(n logn) time, and this is optimal

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry:, SS 2013 13

Page 30: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

Chan’s algorithm

Divide & Conquer (or Graham’s scan + Jarvis march)

and the power of super-exponential search

,FU Berlin, Computational Geometry:, SS 2013 14

Page 31: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

Partition (divide)

P mini-hulls

CMSC 754 Dave Mount

Unfortunately, it is way too slow if there are many points on the hull.So, how can we combine thesetwo insights to produce a faster solution?The first observation needed for a better approach is that, if we hope to achieve a running time ofO(n log h), we can only afford a log factor depending on h. So, if we run Graham’s algorithm, weare limited to sorting sets of size at most h. (Actually, any polynomial in h will work as well. Thereason is that, for any constant c, log(hc) = c log h = O(log h). For example, log h and log(h2) areasymptotically equivalent. This observation will come in handy later on.)How can we use this observation? Suppose that we partitioned the set into roughly n/h subsets,each of size h. We could compute the convex hull of each subset in time O(h log h), which we’llcall a convex mini-hull. The total time to compute all the mini-hulls would be O((n/h)h log h) =O(n log h). We are within our overall time budget, but of course we would still have to figure out howto merge these mini-hulls into the final global convex hull.But wait! We do not know the value of h in advance, so it would seem that we are stuck before weeven get started. We will deal with this conundrum later, but, just to get the ball rolling, suppose fornow that we had an estimate for h, call it h!, whose value is at least as large as h, but not too muchlarger (say h ! h! ! h2). If we run the above partitioning process using h! rather than h, the totalrunning time to compute all the mini-hulls is O(n log h!) = O(n log h).

Original point set

(a) (b)

Partition (h! = 8) and mini-hulls

Figure 1: Partition and mini-hulls.

The partitioning of the points is done by any arbitrary method (e.g., just break the input up into groupsof size roughly h!). Of course, the resulting mini-hulls might overlap one another (see Fig. 1(a)and (b)). Although we presume that h! is a rough approximation to h, we cannot infer anything aboutthe numbers of vertices on the various mini-hulls. They could range from 3 up to h!.

Merging the minis: The question that remains is how to merge the mini-hulls into a single global hull. Theidea is to run Jarvis’s algorithm, but we treat each mini-hull as if it is a “fat point”. At each step,rather than computing the angle from the current hull vertex to every point of the set, we compute thetangent lines of the current hull vertex to each of the mini-hulls, including the mini-hull containingthis vertex. (There are two tangents from a point to a mini-hull, and we need to take care to computethe proper one.) Note that the current vertex is on the global convex hull, so it cannot lie in the interiorof any of the mini-hulls. Among all these tangents, we take the one that yields the smallest externalangle. (The process is illustrated in Fig. 2(a).) Note that, even though a point can appear only once onthe final global hull, a single mini-hull may contribute many points to the final hull.

Lecture 4 2 Spring 2012

,FU Berlin, Computational Geometry:, SS 2013 15

Page 32: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

Merge mini-hulls

k-th step

CMSC 754 Dave Mount

q1

q2q3

q4

pk

pk!1

Jarvis’s algorithm on mini-hulls kth stage of Jarvis’s algorithm

(a) (c)(a) (b)

binary

search

p

K

tangent

Figure 2: Using Jarvis’s algorithm to merge the mini-hulls.

You might think that, since a mini-hull may have as many as h! vertices, there is nothing to be saved incomputing these tangents over the straightforward method. The key is that each mini-hull is a convexpolygon, and hence it has quite a bit more structure than an arbitrary collection of (unsorted) points.In particular, we make use of the following lemma:

Lemma: Consider a convex polygonK in the plane and a point p that is external toK, such that thevertices of K are stored in cyclic order in an array. Then the two tangents from p to K (moreformally, the two supporting lines for K that pass through p) can each be computed in timeO(log m), wherem is the number of vertices ofK.

We will leave the proof of this lemma as an exercise, but the key idea is that, since the vertices of thehull form a cyclically sorted sequence, it is possible to adapt binary search to find the desired pointsof tangency with p (Fig. 2(b)). Using the above lemma, it follows that we can compute the tangentfrom an arbitrary point to a single mini-hull in time O(log h!) = O(log h).The final “restricted algorithm” (since we assume we have the estimate h!) is presented in the codeblock below. (The kth stage is illustrated in Fig. 2(c).) Since we do not generally know what the valueof h is, it is possible that our restricted algorithm may be run with a value of h! that is not within theprescribed range, h ! h! ! h2. (In particular, our final algorithm will maintain the guarantee thath! ! h2, but the lower bound of h may not hold.) If h! < h, when we are running the Jarvis phase,we will discover the error as soon as we encounter more than h! vertices on the hull. If this happens,we immediately terminate the algorithm and announce the algorithm has “failed”. If we succeed incompleting the hull with h! points or fewer, we return the final hull.The upshots of this are: (1) the Jarvis phase never performs for more than h! stages, and (2) ifh ! h!, the algorithm succeeds in finding the hull. To analyze its running time, recall that eachpartition has roughly h! points, and so there are roughly n/h! mini-hulls. Each tangent computationtakes O(log h!) time, and so each stage takes a total of O((n/h!) log h!) time. By (1) the numberof Jarvis stages is at most h!, so the total running time of the Jarvis phase is O(h!(n/h!) log h!) =O(n log h!).

Lecture 4 3 Spring 2012

CMSC 754 Dave Mount

q1

q2q3

q4

pk

pk!1

Jarvis’s algorithm on mini-hulls kth stage of Jarvis’s algorithm

(a) (c)(a) (b)

binary

search

p

K

tangent

Figure 2: Using Jarvis’s algorithm to merge the mini-hulls.

You might think that, since a mini-hull may have as many as h! vertices, there is nothing to be saved incomputing these tangents over the straightforward method. The key is that each mini-hull is a convexpolygon, and hence it has quite a bit more structure than an arbitrary collection of (unsorted) points.In particular, we make use of the following lemma:

Lemma: Consider a convex polygonK in the plane and a point p that is external toK, such that thevertices of K are stored in cyclic order in an array. Then the two tangents from p to K (moreformally, the two supporting lines for K that pass through p) can each be computed in timeO(log m), wherem is the number of vertices ofK.

We will leave the proof of this lemma as an exercise, but the key idea is that, since the vertices of thehull form a cyclically sorted sequence, it is possible to adapt binary search to find the desired pointsof tangency with p (Fig. 2(b)). Using the above lemma, it follows that we can compute the tangentfrom an arbitrary point to a single mini-hull in time O(log h!) = O(log h).The final “restricted algorithm” (since we assume we have the estimate h!) is presented in the codeblock below. (The kth stage is illustrated in Fig. 2(c).) Since we do not generally know what the valueof h is, it is possible that our restricted algorithm may be run with a value of h! that is not within theprescribed range, h ! h! ! h2. (In particular, our final algorithm will maintain the guarantee thath! ! h2, but the lower bound of h may not hold.) If h! < h, when we are running the Jarvis phase,we will discover the error as soon as we encounter more than h! vertices on the hull. If this happens,we immediately terminate the algorithm and announce the algorithm has “failed”. If we succeed incompleting the hull with h! points or fewer, we return the final hull.The upshots of this are: (1) the Jarvis phase never performs for more than h! stages, and (2) ifh ! h!, the algorithm succeeds in finding the hull. To analyze its running time, recall that eachpartition has roughly h! points, and so there are roughly n/h! mini-hulls. Each tangent computationtakes O(log h!) time, and so each stage takes a total of O((n/h!) log h!) time. By (1) the numberof Jarvis stages is at most h!, so the total running time of the Jarvis phase is O(h!(n/h!) log h!) =O(n log h!).

Lecture 4 3 Spring 2012

,FU Berlin, Computational Geometry:, SS 2013 16

Page 33: Computational Geometry: - Convex hull II · Computational Geometry: Convex hull II Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013. Outline Graham’s scan (Andrew’s

Assignment 2

http://page.mi.fu-berlin.de/panos/cg13/exercises/u02.pdf

Due: 22/04!

,FU Berlin, Computational Geometry:, SS 2013 17