9.3 Convex Hull

  • Construct the shortest polygon enclosing a given set of points on a plan.
  • Intuitively, the polygon can be determined by placing a rubber around the set.
 •|-
 ||----
 |    ----
 |•      ---
 |     •   ----
• ---------------
               - •

Graham’s Scan

  • Determine an extreme point with the largest x coordinate.
  • Sort the points in order of increasing angles, relatively to the extreme point.
 • -
b   ---
      ----
  c•---- ----
       -•------
 •----d----------
e              -a•
  • Traverse the points in the sorted order
  • Adding a point less than 180 degrees
  • Backtrack when making a larger turn.
  b
 •|--
  ||----
  •c   ---
        d----
 e     •    ----
•              -•a
         b
 •|--
  ||||--
  •c-- ----
    --- d ---
 e     •     ---
•              -•a
      
  b
 •|--
  | ----
  •c- ||||-
    --| d|---
 e---|-• |- ----
•    |||||     -•a
         b
 •|---
  |  ---
  •c-  ----
    --- d ----
 e     •     ---
•               •a
      
  b
 •|--
  |  ---
  •c   ----
        d ---
 e     •     ---
•              -•a
         b
 •|--
  ||||--
  •c - ----
 ||||-  d ---
 e     •    ----
•              -•a
      
  b
 •|--
  | ----
  •c   ---
        d ---
 e     •    ----
•              -•a
         b
 •---
     ---
  •c   ----
        d ----
 e     •     ---
•              -•a
      
  b
 •--|
 |||----
 |•c   ----
 |      d ---
 e     •    ----
•              -•a
         b
 •----
 |   ---
 |•c   ----
 |||    d ----
 e-----•     ---
•     ----------•a

[applet]