Convex hulls Quickhull - PowerPoint PPT Presentation

About This Presentation
Title:

Convex hulls Quickhull

Description:

Quickhull Quicksort The Quickhull algorithm is based on the Quicksort algorithm. Recall how quicksort operates: at each level of recursion, an array of numbers to be ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 21
Provided by: Mik126
Learn more at: http://www.cs.ucf.edu
Category:

less

Transcript and Presenter's Notes

Title: Convex hulls Quickhull


1
Convex hullsQuickhull
Quicksort The Quickhull algorithm is based on the
Quicksort algorithm. Recall how quicksort
operates at each level of recursion, an array
of numbers to be sorted is partitioned into two
subarrays, such that each term of the first
(left) subarray is not larger than each term of
the second (right) subarray.
Two pointers to the array cells (LEFT and
RIGHT) initially point to the opposite extreme
ends of the array. LEFT and RIGHT move towards
each other, one cell at a time. At any given
time, one pointer is moving and one is not. If
the numbers pointed to by LEFT and RIGHT
violate the desired sort order, they are swapped,
then the moving pointer is halted and the halted
pointer becomes the moving pointer. When the two
pointers point to the same cell, the array is
split at that cell and the process recurses on
the subarrays. Quicksort runs in expected O(N
log N) time, if the subarrays are well
balanced, but can require as much as O(N2) time
in the worst case.
2
Convex hullsQuickhull
Quickhull overview Quickhull operates in a
similar manner. It recursively partitions the
point set S, so as to find the convex hull for
each subset. The hull at each level of the
recursion is formed by concatenating the hulls
found at the next level down.
3
Convex hullsQuickhull
Initial partition The initial partition of S is
determined by a line L through the points l, r ?
S with the smallest and largest abscissa. S(1) ?
S is the subset of S on or above L. S(2) ? S is
the subset of S on or below L. Note that S(1),
S(2) is not a strict partition of S, as S(1) ?
S(2) ? l,r. This is not a difficulty. The
idea now is to construct hulls H(S(1)) and
H(S(2)), then concatenate them to get H(S). The
process is the same for S(1) and S(2), we
consider S(1).
S(1)
r
S(2)
l
L
4
Convex hullsQuickhull
Finding the apex Find the point h ? S(1) such
that (1) triangle hlr has the maximum area of all
triangles plr p ? S(1), and if there are gt 1
triangles with maximum area, (2) the one where
angle hlr is maximum. This condition ensures
that h ? H(S). Why? Construct a line parallel to
line L through h, call it L?. There will be no
points of S(1) (or S) above L?, by condition
(1). There may be other points on L?, but h will
be the leftmost, by condition (2), hence it is
not a convex combination of any two points of S.
? h ? H(S). Apex h can be found in O(N) time by
checking each point of S(1).
h
S(1)
L?
r
l
L
5
Convex hullsQuickhull
Partitioning the point set Construct two directed
lines, L1 from l to h, and L2 from h to r. Each
point of S(1) is classified relative to L1 and
L2 (e.g., point-line classification). No point
can be to the left of both L1 and L2. Points to
the right of both are not in H(S), as they are
within triangle hlr, and are eliminated from
further consideration. Points left of L1 are
S(1,1). Points left of L2 are S(1,2).
S(1,2)
h
S(1,1)
r
L2
l
L
eliminated
L1
6
Convex hullsQuickhull
Recursion The process recurses on S(1,1) and are
S(1,2). (set, left endpoint, right endpoint)
(S(),l,r) (S(,1),l,h) (S(,2),h,r)
S(1,2)
h
L1
S(1,2,2)
r
L2
l
L
The recursion continues until S() has 0
points, i.e., all internal points have been
eliminated, which implies that segment lr is an
edge of H(S).
7
Convex hullsQuickhull
Geometric primitives The geometric primitives
used by this algorithm are 1. Point-line
classification 2. Area of a triangle Both of
these require O(1) time.
8
Convex hullsQuickhull
Initial partition, revisited The preceding
explanation, while intuitive and thus
useful, introduces an anomaly l, r are in both
S(1) and S(2). This is a problem because l, r
will end up in both hulls. To the avoid this,
base the initial partition on l0 (x0, y0), the
point of S with smallest abscissa, and r0 (x0,
y0 - ?), where ? is an arbitrarily small
constant. This effectively selects the initial
line as a vertical line by l0.
S(1)
l0
L1
h
S
L2
r0
S(2)
L
9
Convex hullsQuickhull
General function S is assumed to have at least 2
elements (the recursion ends otherwise). FURTHEST(
S, l, r) is a function, not given here, that
finds the apex point h as previously defined. The
operator denotes list concatentation. Procedure
QUICKHULL returns an ordered list of
points. 1 procedure QUICKHULL(S, l,
r) 2 begin 3 if S l, r then 4 return (l,
r) / lr is an edge of H(S) / 5 else 6 h
FURTHEST(S, l, r) 7 S(1) p ? S ? p is on or
left of line lh 8 S(2) p ? S ? p is on or
left of line hr 9 return QUICKHULL(S(1), l, h)
(QUICKHULL(S(2), h, r) -
h) 10 end 11 end Initial call 1 begin 2 l0
(x0, y0) / point of S with smallest abscissa
/ 3 r0 (x0, y0 - ?) 4 result QUICKHULL(S,
l0, r0) - r0 / The point r0 is eliminated from
the final list/ 5 end
10
Convex hullsQuickhull
Analysis Worst case time O(N2) Expected time
O(N log N) Storage O(N2) At each level of the
recursion, partitioning S into S(1) and
S(2) requires O(N) time. If S(1) and S(2) were
guaranteed to have a size equal to a fixed
portion of S, and this held at each level, the
worst case time would be O(N log N). However,
those criteria do not apply S(1) and S(2) may
have size in O(N) (they are not balanced). Hence
the worst case time is O(N2), O(N) at each of
O(N) levels of recursion. The same applies to
storage.
11
Convex hullsDivide-and-conquer
Divide-and-conquer design goal QUICKHULL
recursively subdivides point set S, and assembles
the convex hull H(S) by merging the subproblem
results. Advantages 1. Subdivision allows
parallelization 2. Merge process is very simple
(concatenation) Disadvantage 1. Inability to
control or guarantee subproblem size results in
suboptimum worst case time performance. We seek
a divide-and-conquer algorithm which divides the
problem into subproblems of approximately equal
size.
12
Convex hullsDivide-and-conquer
Union of convex hulls, 1 Suppose we have S and
want to compute H(S). Further suppose S has been
partitioned into S1 and S2, each containing half
the points of S. If H(S1) and H(S2) are found
separately (recursively), how much additional
work is required to compute H(S1 ? S2), i.e.,
H(S)? In other words, is it easier to find H(S)
H(S1 ? S2) given H(S1) and H(S2) than to find
H(S) directly? To do so, we use the
relation H(S1 ? S2) H(H(S1) ? H(S2)) The
convex hull of the union of the two subsets is
the same as the convex hull of the union of the
convex hulls of the two subsets.
13
Convex hullsDivide-and-conquer
Union of convex hulls, 2 The relation is H(S1 ?
S2) H(H(S1) ? H(S2)) Computing the convex hull
of the union of convex hulls is made simpler
because H(S1) and H(S2) are convex polygons and
thus have an ordering on their vertices. HULL OF
UNION OF CONVEX POLYGONS INSTANCE Convex
polygons P1 and P2. QUESTION Find the convex
hull of their union. This problem is the merge
step of a divide-and-conquer algorithm for convex
hull construction. An efficient algorithm for the
merge is necessary for an efficient
divide-and-conquer algorithm.
H(S1)
H(S2)
14
Convex hullsDivide-and-conquer
Overview of divide-and-conquer algorithm 1. If
S ? k0 (k0 is a small integer), construct the
convex hull directly by some method and stop,
else go to step 2. (For example, for k0 3 the
hull is a triangle, O(1).) 2. Partition the set S
arbitrarily into two subsets S1 and S2 of
approximately equal sizes. 3. Recursively find
the convex hulls H(S1) and H(S2). 4. Merge the
two hulls together to form H(S). Let U(N) denote
the time needed to find the hull of the union
of two convex polygons (convex hulls), each with
N/2 vertices. Let T(N) is the time required to
find the convex hull of N points.
T(N) ? 2T(N/2) U(N)
total time subproblem time merge time If
U(N) ? O(N), then T(N) ? O(N log N) (by
recurrence relation), so we seek an O(N) merge
algorithm, i.e. an O(N) convex polygon union
algorithm.
15
Convex hullsDivide-and-conquer
Merge algorithm, 1 This procedure finds the
convex hull of the union of two convex polygons
P1 and P2. 1. Find a point p that is internal to
P1 (e.g. centroid). Note that this point p will
be internal to H(P1 ? P2). 2. Determine whether
or not p is internal to P2. This can be done in
O(N) time (convex polygon inclusion). If p is
not internal to P2, go to step 4. 3. Point p is
internal to P2. The vertices of both P1 and
P2 occur in sorted angular order about p. Merge
the lists of vertices in O(N) time to obtain a
sorted list of the vertices of both P1 and
P2. Go to step 5.
P1
P2
p
16
Convex hullsDivide-and-conquer
Merge algorithm, 2 4. Point p is not internal to
P2. Relative to p, polygon P2 lies in a wedge
whose apex angle is ? ?. The wedge is delimited
by two vertices of P2, call them u and v, which
can be found in O(N) time by a single pass around
P2. Vertices u and v partition P2 into two
chains of vertices that are monotonic in polar
angle w.r.t. p, with one chain increasing and
the other decreasing. The chain convex towards p
can be discarded, because its vertices will be
internal to H(S1 ? S2). The other chain of P2
and all of P1 constitute two lists of at
most O(N) total vertices that occur in sorted
angular order around p. This can be merged in
O(N) time to form a list of vertices of P1 ? P2,
sorted about p.
17
Convex hullsDivide-and-conquer
Merge algorithm, 3 5. Use the Graham scan on the
sorted list to construct the convex hull of the
vertices on the list, which requires O(N) time.
If polygon P1 has m vertices and polygon P2 has n
vertices, this algorithm constructs H(P1 ? P2) ?
O(m n)? O(N) time. As mentioned, an O(N) merge
gives an O(N log N) divide-and-conquer algorithm
for convex hull.
18
Convex hullsDivide-and-conquer
Supporting lines, 1 A by-product of the convex
hull union algorithm is a method of determining
supporting lines of two convex hulls. A
supporting line of a convex polygon P is a
straight line L passing through a vertex of P
such that the interior of P lies entirely to one
side of L. The idea is analogous to the notion of
tangent for circles.
P
L
19
Convex hullsDivide-and-conquer
Supporting lines, 2 Two convex polygons P1 and
P2, with n and m vertices, such that one is not
entirely contained within the other, have common
supporting lines. The number of common supporting
lines is ? 2 and ? 2min(n,m).
P1
P2
20
Convex hullsDivide-and-conquer
Supporting lines, 3 Once the convex hull of the
union of P1 and P2 has been constructed, common
supporting lines can be found. Scan the vertex
list of H(P1 ? P2) any pair of consecutive
vertices where one originated in P1 and the other
in P2 defines a common supporting line.
Write a Comment
User Comments (0)
About PowerShow.com