Why Graham-Scan Needs to Sort Vertices Before Scanning - PowerPoint PPT Presentation

About This Presentation
Title:

Why Graham-Scan Needs to Sort Vertices Before Scanning

Description:

Why Graham-Scan Needs to Sort Vertices Before Scanning Bill Thies November 12, 2004 6.046 Recitation Supplement Graham Scan: Sorting Step The first stage of Graham ... – PowerPoint PPT presentation

Number of Views:75
Avg rating:3.0/5.0
Slides: 26
Provided by: BillT82
Category:

less

Transcript and Presenter's Notes

Title: Why Graham-Scan Needs to Sort Vertices Before Scanning


1
Why Graham-Scan Needs toSort Vertices Before
Scanning
  • Bill Thies
  • November 12, 2004
  • 6.046 Recitation Supplement

2
Graham Scan Sorting Step
  • The first stage of Graham-Scan sorts the points
    by their polar angle from the bottom-left vertex,
    p0
  • In recitation, we asked would the scanning
    phase of Graham-Scan work on any simple polygon?
    That is, can you omit this sorting phase if you
    start from a simple polygon?
  • The answer is NO.

p0
3
Graham Scan Sorting Step
  • The first stage of Graham-Scan sorts the points
    by their polar angle from the bottom-left vertex,
    p0
  • In recitation, we asked would the scanning
    phase of Graham-Scan work on any simple polygon?
    That is, can you omit this sorting phase if you
    start from a simple polygon?
  • The answer is NO.

p0
4
Graham Scan Sorting Step
  • The first stage of Graham-Scan sorts the points
    by their polar angle from the bottom-left vertex,
    p0
  • In recitation, we asked would the scanning
    phase of Graham-Scan work on any simple polygon?
    That is, can you omit this sorting phase if you
    start from a simple polygon?
  • The answer is NO.

p6
p3
p4
p5
p2
p1
p0
5
Graham Scan Sorting Step
  • The first stage of Graham-Scan sorts the points
    by their polar angle from the bottom-left vertex,
    p0
  • In recitation, we asked would the scanning
    phase of Graham-Scan work on any simple polygon?
    That is, can you omit this sorting phase if you
    start from a simple polygon?
  • The answer is NO.

p6
p3
p4
p5
Simple polygon (not convex)
p2
p1
p0
6
Graham Scan on Simple Polygons
  • The first stage of Graham-Scan sorts the points
    by their polar angle from the bottom-left vertex,
    p0
  • In recitation, we asked would the scanning
    phase of Graham-Scan work on any simple polygon?
    That is, can you omit this sorting phase if you
    start from a simple polygon?
  • The answer is NO.

p6
p3
p4
p5
Simple polygon (not convex)
p2
p1
p0
7
Counter-Example
  • Consider the same set of points with the
    following simple polygon

8
Counter-Example
  • Consider the same set of points with the
    following simple polygon
  • Run Grahams Scan starting from p0

p3
p2
Stack
p4
p6
p5
p1
p0
9
Counter-Example
  • Consider the same set of points with the
    following simple polygon
  • Run Grahams Scan starting from p0

p3
p2 p1 p0 Stack
p2
p4
p6
p5
p1
p0
10
Counter-Example
  • Consider the same set of points with the
    following simple polygon
  • Run Grahams Scan starting from p0

p3
p2
p2 p1 p0 Stack
p4
p6
p5
p1
p0
p0
11
Counter-Example
  • Consider the same set of points with the
    following simple polygon
  • Run Grahams Scan starting from p0

p3
p2
p3 p2 p1 p0 Stack
p4
p6
p5
p1
p0
p0
12
Counter-Example
  • Consider the same set of points with the
    following simple polygon
  • Run Grahams Scan starting from p0

p3
p2
p3 p2 p1 p0 Stack
p4
p6
p5
p1
p0
p0
13
Counter-Example
  • Consider the same set of points with the
    following simple polygon
  • Run Grahams Scan starting from p0

p3
p2
p4 p3 p2 p1 p0 Stack
p4
p6
p5
p1
p0
p0
14
Counter-Example
  • Consider the same set of points with the
    following simple polygon
  • Run Grahams Scan starting from p0

p3
p2
p4 p3 p2 p1 p0 Stack
p4
p6
p5
p1
p0
p0
15
Counter-Example
  • Consider the same set of points with the
    following simple polygon
  • Run Grahams Scan starting from p0

p3
p2
p4 p3 p2 p1 p0 Stack
p4
p6
p5
p1
p0
p0
16
Counter-Example
  • Consider the same set of points with the
    following simple polygon
  • Run Grahams Scan starting from p0

p3
p2
p3 p2 p1 p0 Stack
p4
p6
p5
p1
p0
p0
17
Counter-Example
  • Consider the same set of points with the
    following simple polygon
  • Run Grahams Scan starting from p0

p3
p2
p3 p2 p1 p0 Stack
p4
p6
p5
p1
p0
p0
18
Counter-Example
  • Consider the same set of points with the
    following simple polygon
  • Run Grahams Scan starting from p0

p3
p2
p3 p2 p1 p0 Stack
p4
p6
p5
p1
p0
p0
19
Counter-Example
  • Consider the same set of points with the
    following simple polygon
  • Run Grahams Scan starting from p0

p3
p2
p5 p3 p2 p1 p0 Stack
p4
p6
p5
p1
p0
p0
20
Counter-Example
  • Consider the same set of points with the
    following simple polygon
  • Run Grahams Scan starting from p0

p3
p2
p5 p3 p2 p1 p0 Stack
p4
p6
p5
p1
p0
p0
21
Counter-Example
  • Consider the same set of points with the
    following simple polygon
  • Run Grahams Scan starting from p0

p3
p2
p6 p5 p3 p2 p1 p0 Stack
p4
p6
p5
p1
p0
p0
22
Counter-Example
  • Consider the same set of points with the
    following simple polygon
  • Run Grahams Scan starting from p0

p3
p2
p6 p5 p3 p2 p1 p0 Stack
p4
p6
p5
p1
p0
p0
At end, get convex hull ltp0, p1, p2, p3, p5,
p6gt But actually, convex hull ltp0, p1, p2, p3gt
23
Counter-Example
  • Consider the same set of points with the
    following simple polygon

p3
p2
p6 p5 p3 p2 p1 p0 Stack
p4
p6
p5
original
p1
p0
p0
What went wrong? Vertex p3 was not visible
from p0, so the line p3-gtp5 crossed p6-gtp0
whenbuilding the convex hull. That is, the
polygon became non-simple during course of the
algorithm.
24
Graham-Scan Builds Star-Shaped Polygons
  • When vertices are sorted by polar angle from p0,
    all other vertices are visible from p0 in
    resulting polygon
  • A polygon with a point visible from each vertex
    is called star-shaped (CLRS p. 957, Ex. 33.3-4).
  • Graham-Scan works for all star-shaped
    polygons,but not for all simple ones

p6
p3
p4
p5
p2
p1
p0
25
For More Information
  • There do exist linear-time algorithms for
    building the convex hull of a simple polygon.
    Many of the first algorithms proposed were
    actually incorrect!See here for an interesting
    history
  • http//cgm.cs.mcgill.ca/athens/cs601/intro.html
  • Is the question we considered a million-dollar
    question? Probably not, but it can be worth up
    to 200! Click here for a good
    timehttp//answers.google.com/answers/threadview
    ?id137349
Write a Comment
User Comments (0)
About PowerShow.com