Convex Sets & Concave Sets

Document Sample
Convex Sets & Concave Sets Powered By Docstoc
					   Convex Sets & Concave Sets
A planar region R is called convex if and only if for any pair
of points p, q in R, the line segment pq lies completely in R.

Otherwise, it is called concave.

                                                 p
                p

          R1                                R2
                    q

                                                 q

               Convex                         Concave
An Example


      4

  1       2




      3
                       Convex Hull
The convex hull CH(Q) of a set Q is the smallest convex region
that contains Q.


                                                               Rubber band




When Q is finite, its convex hull is the unique convex polygon whose vertices
are from Q and that contains all points of Q.
    The Convex Hull Problem
Input: a set P = { p1 , p2 , …, pn } of points

Output: a list of vertices of CH(P) in counterclockwise order.

Example                         p5

               p9         p6                  p7
                                    p1
               p2                        p4
                               p3                  p10
                         p8


   Output: p5 , p9 , p2 , p8 , p10, p7 .
     Edges of a Convex Hull
For every edge both endpoints p, q Î P.
All other points in P lie
   to the same side of the line passing through p and q, or
   on the line segment pq.

                            q    r
                                        p
    Polar Angle

y


               q


         polar angle
p
                       x


          r
   An Example of Graham Scan
Sort by polar angle.

                        p9                 p6
                                   p7              p4
       p11
                              p8
                  p10                    p5
                                                    p3

                                              p2         p1


                                p0 (with the minimum y-coordinate)
                                                        How to break a tie?
  Labels are in the polar angle order.
 (What if two points have the same polar angle?)
      Stack Initialization

                                   p6
             p9
                        p7              p4
p11
                  p8                               S
       p10                        p5
                                         p3        p2
                                                   p1
                             p2               p1
                                                   p0

                   p0
                                 p6
            p9
                       p7             p4
p11
                 p8                              S
      p10                    p5
                                       p3        p3
                                                 p1
                            p2              p1
                                                 p0

                  p0
                                 p6
            p9
                       p7                  p4
p11
                 p8                                  S
      p10                    p5
                                      p3             p4
                                                     p1
                            p2                  p1
                                                     p0

                  p0
                                 p6
            p9                                       S
                       p7                  p4
p11
                 p8                                  p5
      p10                    p5
                                      p3             p4
                                                     p1
                            p2                  p1
                                                     p0

                  p0
                                 p6
            p9                                       S
                       p7                  p4
p11
                 p8                                  p6
      p10                    p5
                                      p3             p4
                                                     p1
                            p2                  p1
                                                     p0

                  p0
                                                     S

                                 p6                  p8
            p9
                       p7                  p4        p7
p11
                 p8                                  p6
      p10                    p5
                                      p3             p4
                                                     p1
                            p2                  p1
                                                     p0

                  p0
                                                     S

                                 p6
            p9
                       p7                  p4        p7
p11
                 p8                                  p6
      p10                    p5
                                      p3             p4
                                                     p1
                            p2                  p1
                                                     p0

                  p0
                                                 S


                             p6                  p10
            p9
                                       p4        p9
p11                    p7
                 p8                              p6
      p10                   p5
                                  p3             p4
                                                 p1
                       p2                   p1
                                                 p0

                  p0
                                                 S


                             p6                  p11
            p9
                                       p4        p9
p11                    p7
                 p8                              p6
      p10                   p5
                                  p3             p4
                                                 p1
                       p2                   p1
                                                 p0

                  p0
                 Finish
                                                  S

                              p6                  p11
            p9
                                        p4        p9
p11                     p7
                  p8                              p6
      p10                    p5
                                   p3             p4
                                                  p1
                        p2                   p1
                                                  p0

                   p0
                           Graham’s Scan

                                          pk
        candidates
        for vertices   pj                 pj   Non-vertices   pl     finish
                            Every point        of CH(P)
start   of CH(P)
                       pi   in P is       pi   determined     pi        ps
                            pushed onto        so far are
  p2                   ·                  ·    popped         ·         ·
                       ·
                            S once        ·                   ·         ·
  p1                   ·                  ·                   ·         ·


  p0                   p0                 p0                  p0        p0
                                                                   vertices of
                                                                   CH(P) in the
                                                                   counter-
                                                                   clockwise
                                                                   order.
The Graham Scan Algorithm
Graham-Scan(P)
    let p be the point in P with minimum y-coordinate
         0
    let á p , p , …, p ñ be the remaining points in P
           1 2        n–1
         sorted in counterclockwise order by polar angle around p .
                                                                 0
    Top[S] ¬ 0
    Push(p , S)
            0
    Push(p , S)
            1
    Push(p , S)
            2
    for i ¬ 3 to n - 1
         do while p makes a nonleft turn from the line segment
                    i
                  determined by Top(S) and Next-to-Top(S)
               do Pop(S)
            Push(S, p i )
    return S
  Correctness of Graham’s Scan

Theorem If Graham-Scan is run on a set P of at least three
   points, then a point of P is on the stack S at termination
   if and only if it is a vertex of CH(P).
                Running time

           #operations     time / operation    total

     Finding     1              Q(n)            Q(n)
       p0
     Sorting   1              O(n lg n)       O(n lg n)
     Push     n                O(1)             Q(n)
     Pop     £n-2              O(1)             O(n)
               Why?



The running time of Graham’s Scan is O(n lg n).
                         Jarvis’ March
  A “package wrapping” technique
                                         (smallest polar
                         p4           p3 angle w.r.t. p2)

    (smallest polar                               p2 (smallest polar
     angle w.r.t. p )                                 angle w.r.t. p )
                     4                                             1
Left                                                          Right
chain                                                         chain
        p5                                            p1
                                               (smallest polar
                p6                              angle w.r.t. p )
                                                              0
 (smallest polar
                              p0 (lowest point)
  angle w.r.t. p )
               5
 Running Time of Jarvis’s March

Let h be the number of vertices of the convex hull.

        For each vertex, finding the point with the minimum
        Polar angle, that is, the next vertex, takes time O(n).


          Comparison between two polar angles can be done
          using cross product.



Thus O(nh) time in total.

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:0
posted:7/19/2013
language:Unknown
pages:23
Jun Wang Jun Wang Dr
About Some of Those documents come from internet for research purpose,if you have the copyrights of one of them,tell me by mail vixychina@gmail.com.Thank you!