Kir CK Patrick Seidel

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 42

An interesting geometric

problem
CS F364
Instructor: Dr. Tathagata Ray
So here we start
• Find the convex hull of a given set of points on
a plane?

• Convex: A subset S of the plane is called


convex iff for any pair of points p, q in S the
line segment (pq) is completely contained in S.
Convex Hull
• Definition 1: The convex hull CH(S) of a set is
the smallest convex set that contains S.

• Definition 2: Alternatively, it is the


intersection of all convex sets that contain S.
Punch the nails!
Another definition

• Definition3: It is the unique convex polygon


whose vertices are points from P and that
contains all points of P
Problem Statement

• Given a set P = {p1, p2, …, pn} of points in the


plane, compute a list that contains those
points from P that are the vertices of Convex
Hull of P, listed in clockwise order.
Exploit the definition
• From definition 3, we have to look for a
convex polygon whose vertices are from P.

• So what the edges of CH(P) are?


Exploit the definition
• Both endpoints p and q of such an edge are points
of P such that if we draw a directed line from p to q
then all the points of P must lie to the right of this
line.

• Conversely, of all points of P \ {p,q} lie to the right


of the directed line through p and q then (pq) is an
edge of CH(P).
• Assume: points are in general position that means
no 3 or more points are collinear.
So an algorithm
• SLOWCONVEXHULL(P)
• Input: A set P of points in the plane.
• Output: A list L containing the vertices of CH(P) in clockwise
order.
1. E←Φ
2. For all ordered pairs (p,q) \in P X P with p not equal to q
3. Do valid ← true
4. For all points r \in P not equal to p or q
5. Do if r lies to the left of the directed line from p to q.
6. Then valid ← false.
7. If valid then Add the directed edge pq to E.
8. From the set E of edges construct a list L of vertices CH(P),
sorted in clockwise order.
Exercise

• Analyze the time complexity of


SLOWCONVEXHULL.
The Kirckpatrick-Seidel Algorithm
• Divide and Conquer:
– Divide the problem into subproblems.
– Solve the subproblems (use brute force if they are
small enough else recurse).
– Merge the subsolutions.

• Helps parallelizability !
Apply it on convex hull
• Input point set P.
• Divide it into P1 and P2.
• Lets say somehow we can find CH(P1) and
CH(P2).
• Great property CH(P) = CH( CH(P1) U CH (P2) )
The Algorithm
• procedure divide-and-conquer(S);
• 1. If |S|< ko (where ko is some small integer), then
construct the convex hull of S by some other
method. If not, go to step 2.
• 2. Partition S into two subsets ,S1 and S2 of
approximately equal size.
• 3. Recursively find the convex hulls of S1 and S2.
• 3. Merge the two convex hulls CH(S1) and CH(S2)
together to form CH(S).
How will you merge
How will you merge
Upper Bridge
u2
u1

l1
l2
Lower Bridge
How will you merge
Upper Bridge
u2
u1

Delete

l1
l2
Lower Bridge
The Kirkpatrick-Seidel algorithm
• A variation of divide and conquer strategy.

• Also, called prune and search strategy.


The Kirkpatrick-Seidel Algorithm
procedure kirkpatrick-seidel(S);
1. Let pmin and pmax, be the points of S with the least
and largest x-coordinate, respectively.
2. If there are two or more such pmin (pmax), pick from
them the point with the largest y coordinate and
call it pumin (pumax).
• T := {pumin ,pumax)}U {p in S | x(pumin ) < x(p) <
x(pumax) }.
• UPPER-HULL(pumin ,pumax, T);
The Kirkpatrick-Seidel Algorithm
• If there are two or more such pmin or pmax, pick
from them the point with the least y
coordinate as plmin, or plmax, as the case may
be.
• T := {plmin ,plmax)}U {p in S | x(plmin ) < x(p) <
x(plmax) }.
• LOWER-HULL(plmin ,plmax, T);
The Kirkpatrick-Seidel Algorithm
4. (UPPER-HULL (LOWER-HULL) will return the
points on the upper (lower) hull of S in
clockwise order, in the form of a doubly linked
list.) Concatenate the list UPPER-HULL returns
to the list that LOWER-HULL returns. We now
have the convex hull of S in clockwise order.
The algorithm
procedure UPPER-HULL(pmin ,pmax, T);
1. Let pmin and pmax, be the points of S with the
least and largest x-coordinate, respectively

pmin pmax
The algorithm
2. Find the median of the x-coordinates of the points in T i.e.
find an a such that
• x(p) ≤ a for |T|/2 points in T and
• x(p) ≥ a for |T|/2 points in T
• Let L be the vertical line x = a. Let Tleft be the points of T to the
left of L. Let Tright be the points of T to the right of L.

Tleft L Tright

pmin pmax
The algorithm
• 3. Define the upper bridge to be the segment such that its
left end-point pl lies in Tleft and its right end-point pr, lies in
Tright, and it is a supporting line of T. Clearly, the upper bridge
is a part of the upper convex hull.
• We will show later that there is an algorithm to determine
upper bridges efficiently (pl, pr) := UPPER-BRIDGE(T, L);

Tleft pl L pr Tright

pmin pmax
Definition of Supporting Line
• Supporting line of S is a nonvertical straight
line which contains at least one point of S but
has no points of S above it.

It is a supporting
line

Not a
supporting line
The algorithm
4. Since pmax, pl, pr, and pmin, are all points in T , and they form a
convex quadrilateral, we can discard all points of T that fall within
this quadrilateral , since they cannot form the vertices of the upper
hull.
• Tleft:= {pl} U all the points of Tleft to the left of the line through pmin
and pl;
• Tright := {pr} U all the points of Trightto the right of the line through pr
and pmax;
T pl L pr Tright
left

pmin pmax
The algorithm
• UPPER-HULL(pmin, pl, Tleft) * UPPER-HULL(pr,
pmax, Tright), where * represents list
concatenation of doubly linked lists.
• Find the LOWER-HULL(pmax, pr, Tright) * LOWER-
HULL(pl, pmin, Trleft),
Finding the Upper Bridge

• Lemma 1: Let p and q be a pair of points of S.


If x(p) = x(q) and y(p) > y(q) then q cannot be a
bridge point.
• Lemma 2: Let p and q be a pair of points of S with
x(p) < x(q) and let mpq be the slope of the straight
line h through p and q. Let mb be the slope of
upper bridge.
– If mpq > mb , then p cannot be a bridge point because a
bridge passing through p with slope mb will have q
above it.
– If mpq < mb , then q cannot be a bridge point because a
bridge passing through q with slope mb will have p
above it.
Lemma 2
Definition of Supporting Line
• Supporting line of S is a nonvertical straight
line which contains at least one point of S but
has no points of S above it.

It is a supporting
line

Not a
supporting line
• Lemma 3: Let h be a supporting line of S with
slope mh, and let the point(s) of S that it
contains belong to the upper hull.
– mh > mb iff h contains only points of S that are to
the left of or on L (dividing line).
– mh < mb iff h contains only points of S that are to
the right of L .
Lemma 3
Lemma 2 + Lemma 3
• Corollary : Let p, q be points in S with x(p) <
x(q), and h be any supporting line of S. Then
– If h contains only points of S to the left of or on L
(means mh > mb ) and mpq > mh ( > mb), then using
lemma 2, p is not a candidate for the end point of
the bridge.
– If h contains only points of S to the right of L
(means mh < mb ) and mpq < mh ( < mb), then using
lemma 2, q is not a candidate for the end point of
the bridge.
The Upper_Bridge Algo
Analysis
• Theorem: UPPER-BRIDGE runs in O(n) worst
case time.
• Proof: The median finding operation will take
linear time in step 4.
• In step 3, 8 and 9. at least one quarter of the
points of S are eliminated and hence are not
contained in CANDIDATES.
• So the recurrence is f(n) = f(3n/4) + O(n).
• The solution is O(n)
UPPER-HULL
• Claim: UPPER-HULL takes O(N log Hu) time,
where Hu is the number of vertices on the
upper hull, and N is the size of the input.

• Assumption:
– UPPER_BRIDGE () takes linear time.
– Median finding operation is linear time.
• So Step 2 to 4 takes O(N) time.
Let T(n,h) be the recurrence relation . Here c is a
Constant and n≥h>1. hl and hr are number of upper
hull edges in recursive calls for left and right side.

 cn ifh  2
T (n, h)   n n
cn  max{T ( , hl )  T ( , hr ) | hl  hr  1  h} o.w
2 2
f ( n, h )
Reference
• http://graphics.stanford.edu/courses/cs268-
16-fall/Notes/KirkSeidel.pdf
• Suneeta Ramaswami. Convex Hulls:
Complexity and Applications (A Survey) .
Technical report. Dept of Computer Science,
Upenn, 1993.

You might also like