18
CONVEX HULL Yitian Huang & Zhe Yang Apr 22, 2016 1

Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and Zhe Yang

Embed Size (px)

Citation preview

PowerPoint Presentation

Convex HullYitian Huang & Zhe YangApr 22, 20161

1

Definition Of Convex HULLSimply, given a set of points P in a plane, the convex hull of this set is the smallest convex polygon that contains all points of it.

(A set of points and its convex hull)2

We will introduce an O(nlogh) algorithm known as Chans Algorithm, where h refers the number of points in the hull.

However, Chans Algorithm is based on other two algorithms known as Jarviss Algorithm O(nh) and Grahams Algorithm O(nlogn).

So, we will talk about these two algorithms first. 3

Before StartCounterclockwise and ClockwiseIts relative In this presentationUse function orient(p, q, i) to calculate the relationship of pq and pi. Obviously, orient(p, q, i) = - orient(p, i, q)Extreme pointsThere will be four extreme pointsAll of them MUST be in the hull lastlyMost algorithm choose to start with one of the extreme points.In this presentationAll algorithms will start will the left most point.

4

Two concepts4

Jarviss Algorithm

5

5

Jarviss AlgorithmPerhaps the simplest algorithm for computing Convex HullIn the two-dimensional case the algorithm is also known as Jarvis march, after R. A. Jarvis, who published it in 1973.It has a more visual name: Gift Wrapping.

6

How it works?

Start with the left most point, l.Let p = l, find out the point q that appears to be furthest to the right to someone standing at p and looking at other points. (by comparing all others points)Thats is: orient(p, q, i) < 0 is always true for all other points.Set q as p, and use p as the start point and use the same method to find the next q.Keep doing step 3, until q is equal to l.

O(n)O(h)Total: O(nh)O(n)

7

Grahams algorithm

8

Grahams algorithmIt is named after Ronald Graham, who published the original algorithm in 1972.Also know as Grahams scan, rst explicitly sorts the points and then scanning algorithm to nish building the hull.Basically, sort + scan.9

How it works?

Start with the left most point, l.Sorts all other points in counterclockwise order around l.Thats is: orient(l, i, i+1) > 0 is always true for all points i.Start with l, let p = l, q = l +1, i = l + 2.Check orient(p, q, i)If < 0, move forward, let p = q, q =i, i = i +1;If > 0, remove q, let p = p-1, q = p ;Keep doing step 4, until all points have been checked.

O(nlogn)O(n)Total: O(nlogn)O(n)SORTSCAN

10

CHANs algorithm

11

Chans Algorithm = Jarvis's + Grahams + ...It was discovered by Timothy Chan in 1993.Its a combination of divide-and-conquer, gift-wrapping and grahams scan.its output-sensitive, which means its running time depends on the size of its output (or input).12

How it works?

Find a magic value of m, which divides all points into n/m subsets, and each subset has m points, approximately.To each subset, use Grahams algorithm to compute its sub-hull.To all sub-hulls, use Jarviss algorithm to compute the final convex hull.Choose one extreme point as the start point, and compare the right tangents of all sub-hulls. Choose the rightest one as the next point.Start with the next point, and do it again, until the next point is equal to the start point

13

Find Magic mThe core of Chans algorithm is how to figure out the value of m. (The object is to make m very close to h, or equal)Chan proposed a amazing trick here:We set a parameter t = 1 and set m = 2^(2^t).Then use this m to execute Chans Algorithm, in step 3, we set a counter for the output number of points in the hull. Once the counter reaches value m, it terminate the algorithm and increment t by 1, re-calculate the value m, and do it again!By doing this, the time for running this algorithm will always be less than O(nlogm).

14

Time ComplexityWe divided points into n/m parts, so each part has m points.Since the algorithm will be terminated when it number of output reaches m, so this step will at most cost O(nlogm), when m is small.For step 2Its O((n/m) * mlogm) = O(nlogm)For step 3Finding one extreme point, O(n).tangentsFinding the right tangents of one sub-hull, O(logm).There are n/m sub-hulls, so O((n/m)logm)There are h points in the hull. O(h*(n/m)logm) = O(nlogh) when h=m.Totally, its O(nlogh).Find a magic value of m, which divides all points into n/m subsets, and each subset has m points, approximately.To each subset, use Grahams algorithm to compute its sub-hull.To all sub-hulls, use Jarviss algorithm to compute the final convex hull.Choose one extreme point as the start point, and compare the right tangents of all sub-hulls. Choose the rightest one as the next point.Start with the next point, and do it again,until the next point is equal to the start point15

16

References[1]. https://en.wikipedia.org/wiki/Chan%27s_algorithm[2]. http://tomswitzer.net/2010/12/2d-convex-hulls-chans-algorithm/[3]. http://jeffe.cs.illinois.edu/teaching/373/notes/x05-convexhull.pdf[4]. http://www.utdallas.edu/~daescu/convexhull.pdf[5]. http://www.geeksforgeeks.org/convex-hull-set-1-jarviss-algorithm-or-wrapping/[6]. http://www.geeksforgeeks.org/convex-hull-set-2-graham-scan/

17

Thank you!Questions?

An example for Gift-wrappingNOT Chans Algorithm!18