Convex Hull in Two Dimensions - PowerPoint PPT Presentation

1 / 46
About This Presentation
Title:

Convex Hull in Two Dimensions

Description:

Convex Hull in Two Dimensions Jyun-Ming Chen Refs: deBerg et al. (Chap. 1) O Rourke (Chap. 3) * – PowerPoint PPT presentation

Number of Views:336
Avg rating:3.0/5.0
Slides: 47
Provided by: jmch6
Category:

less

Transcript and Presenter's Notes

Title: Convex Hull in Two Dimensions


1
Convex Hull in Two Dimensions
  • Jyun-Ming Chen
  • Refs deBerg et al. (Chap. 1)
  • ORourke (Chap. 3)

2
Outline
  • Definitions of CH
  • Algorithms for CH
  • Analysis of algorithms

3
Convex Hull
??(Convex Hull)
  • Definition of convexity
  • Convex hull of a point set S, CH(S)
  • Smallest convex set containing S
  • Intersection of all convex sets containing S

4
Convex Hull
  • Why computing CH?
  • Many reasons e.g., faster collision detection
  • How to compute CH?
  • Good solutions come from
  • A thorough understanding of the geometric
    properties of the problem
  • Proper application of algorithmic techniques and
    data structures

5
General Steps
  • Sketch your problem in general position
  • Observe the desired output and reason about the
    possible steps to get to the goal
  • Check for degeneracy
  • Time/resource complexity
  • General case
  • Best/worst cases

6
Computing CH
  • of a finite set P of n points in 2D
  • Geometric intuition Rubberband analogy
  • Representation
  • Input point set
  • Output CH(P) CW-ordered point set

7
Observation
  • Def convex edges
  • Idea
  • Search through all pairs of points for convex
    edges
  • Form a loop

8
Naïve Algorithm
You can add a break here if you like
9
Analysis of Naïve Algorithm
  • Assumption points are in general position
  • (usually this is done first to simplify the code)
  • (consider the degenerate cases later)
  • How to compute lie to the left of directed
    line?
  • Complexity analysis O(n3)
  • (n2n)/2 pairs, each with n2 other points to
    examine
  • High complexity due to
  • simply translate geometric insight into an
    algorithm in a brute-force manner

10
Considering Degeneracy
  • Collinearity
  • Modify the test to all points to the right, or
    on the line
  • Does this solve the problem?!

11
Degenerate Case (cont)
  • Consider numerical inaccuracy
  • Two possibilities

12
Jarvis March (Gift Wrapping)
  • A modification of naïve algorithm
  • Start at some extreme point, which is guaranteed
    to be on the hull.
  • At each step, test each of the points, and find
    the one which makes the smallest right-hand turn.
    That point has to be the next one on the hull.
  • The final CW loop is the CH.

13
Jarvis March (cont)
  • Complexity
  • Crude count O(n2)
  • Output sensitive
  • O(nh), h of segments on the hull

Worst case
14
A Better Algorithm
  • Sort by x-coord
  • The extreme points must be on the CH
  • Goal in 2 linked lists
  • Upper hull p1 to pn
  • Lower hull pn to p1
  • Idea
  • In CW manner, always making right turns
  • If fail to turn right, delete previous point
    until the turn is correct.

15
(No Transcript)
16
Step-by-step
7
3
5
9
1
6
4
2
8
1,2
17
Step-by-step
7
3
5
9
1
6
4
2
8
1,2,3
18
Step-by-step
7
3
5
9
1
6
4
2
8
1,3
19
Step-by-step
7
3
5
9
1
6
4
2
8
1,3,4
20
Step-by-step
7
3
5
9
1
6
4
2
8
1,3,4,5
21
Step-by-step
7
3
5
9
1
6
4
2
8
1,3,5
22
Step-by-step
7
3
5
9
1
6
4
2
8
1,3,5,6
23
Step-by-step
7
3
5
9
1
6
4
2
8
1,3,5,6,7
24
Step-by-step
7
3
5
9
1
6
4
2
8
1,3,5,7
25
Step-by-step
7
3
5
9
1
6
4
2
8
1,3,7
26
Step-by-step
7
3
5
9
1
6
4
2
8
1,3,7,8
27
Step-by-step
7
3
5
9
1
6
4
2
8
1,3,7,8,9
28
Step-by-step
7
3
5
9
1
6
4
2
8
1,3,7,9 Upper hull completed
29
Algorithm (cont)
  • This is a variation of Graham Scan
  • Proof of correctness p.8
  • Complexity analysis O(n log n)
  • Lexicographical sorting of points O(n log n)
  • Computation of lower hull O(n)
  • Consider the for and while

30
Consider Degeneracy Again
  • Effects on sorting
  • Lexico. ordering
  • Effects on making turns

31
Other Version of Graham Scan
  1. Find an extreme point. This point will be the
    pivot, is guaranteed to be on the hull, and is
    chosen to be the point with smallest y
    coordinate.
  2. Sort the points in order of increasing angle
    about the pivot. We end up with a star-shaped
    polygon (one in which one special point, in this
    case the pivot, can "see" the whole polygon).
  3. Build the hull, by marching around the
    star-shaped poly, adding edges when we make a
    left turn, and back-tracking when we make a right
    turn.

32
Graham Scan (ver2)
  • Also handles collinearity

33
Incremental Algorithm
  • Suitable for dynamic CGeom and 3D hull
  • If pn?CHn-1,
  • CHnCHn-1
  • Else
  • Find two tangents, update CHn

34
Incremental Algorithm
  • Input a set of points P in 2D
  • Output a list L containing the points of CH(P)
    in CCW order
  • 1. Take first three points of P to form a
    triangle
  • 2. For i 4 to n
  • If (pi is in CHi-1) do nothing
  • Else
  • FindTangent (pi, CHi-1)?t1, t2
  • Replace the items t2 t1 in L by t2, pi, t1

35
FindTangent (p, CH)
  • (Go through all points in CH circularly)
  • For each point pi
  • If XOR (p is left_or_on (pi-1,pi), p is
    left_or_on(pi,pi1))
  • Mark pi as the tangent point
  • (There will be two tangent points)
  • Determine t1, t2

36
Incremental Algorithm (cont)
  • Finding Tangents
  • Analysis

37
Quick Hull
38
Quick Hull (cont)
  • Time complexity
  • Find extreme point c O(n)
  • Cost of recursive call
  • T(n) O(n) T(A) T(B)
  • Best case A B n/2
  • T(n) 2T(n/2) O(n) T(n) O(n log n)
  • Worst case A 1, B n-1
  • T(n) T(n-1) O(n) T(n) O(n2)

39
Divide and Conquer Algorithm
  • Computing 3D hull
  • Graham scan (probably not ?angle sort)
  • Preparata and Hong (1977)

a-1 a1 at left side of ab b-1 b1 at left
side of ab
T(n) 2T(n/2) O(n) T(n) O(n log n)
40
Extend to 3D
41
Floating Point Inaccuracies
  • Handled by
  • Interval arithmetic
  • Exact (rational) arithmetic

42
Interval arithmetic
  • Ref http//www.eng.mu.edu/corlissg/VC02/READ_ME.h
    tml

43
Exact Math
  • Rational arithmetic (never floating point)
  • In6 1/12 - 7/9 31/36
  • Out6 - 1/6
  • The Exact Arithmetic Competition Level 0 Tests
  • Ref XR

44
Exercise
  • From this applet, develop a Graham scan algorithm
    that returns a CW-ordered convex hull
  • Express the algorithm in pseudocode. Make sure it
    works for general position and degenerate cases
    (shown right)
  • Run your example on test cases (general position
    and degeneracies)
  • Explain the correctness and time complexity of
    divide-and-conquer algorithm

45
(No Transcript)
46
More reference on the web.
Write a Comment
User Comments (0)
About PowerShow.com