Download presentation
Presentation is loading. Please wait.
Published byAlberta Randall Modified over 9 years ago
1
1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem
2
2 Closest pair problem Given a set of points on the plane, find the two points whose distance from each other is the maximum –What’s the brute-force solution? –An efficient divide-and-conquer solution?
3
3 Convex Hull (CH) Convex Hull (CH) of a set Q of points is the smallest convex polygon P, for which each point in Q is either on the boundary of P or in its interior p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12
4
4 Convex Hull – Jarvis’s March p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Take the horizontal line going through p 0, and gift wrap it around the remaining points by turning the wrap to the left. The first point touched is the next point on CH In this example, it is p 1
5
5 Convex Hull – Jarvis’s March p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Continue gift-wrapping from p 1. Next point is p 3
6
6 Convex Hull – Jarvis’s March p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Continue gift-wrapping from p 3. Next point is p 10
7
7 Convex Hull – Jarvis’s March p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Continue gift-wrapping from p 10. Next point is p 12
8
8 Convex Hull – Jarvis’s March p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Continue gift-wrapping from p 12. Next point is p 0
9
9 Convex Hull – Jarvis’s March p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Continue gift-wrapping from p 12. Next point is p 0. We are done now.
10
10 Jarvis’s March – Running Time O(n*h), where h is the number of points on the convex hull –If h is O(logn), then we get a running time of O(nlogn) –If h is O(n), then we a quadratic running time of O(n 2 ) –Can we make sure that the running time is always O(nlogn)? Graham’s scan
11
11 Graham’s Scan Let p 0 be the point in Q with the min y-coordinate or the leftmost such point in the case of a tie Let be the remaining points in Q sorted by polar angle in counter-clockwise order around p 0. If more than one point has the same angle, remove all but the one that is farthest from p 0 p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12
12
12 Graham’s Scan Maintain a stack S of candidate points Each point of the input set Q is pushed once onto the stack, and the points that are not vertices of CH(Q) are eventually popped off the stack When the algorithm terminates, S contains exactly the vertices of CH(Q) in counter- clockwise order of their appearance on the boundary
13
13 Graham’s Scan - Algorithm Push(p 0, S); Push(p 1, S); Push(p 2, S); for i=3 to m do while the angle formed by points NEXT_TO_TOP(S), TOP(S) and p i makes a non-left turn do Pop(S); endwhile Push(p i, S); endfor return S;
14
14 Convex Hull – Initial State p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Stack p0p0 p1p1 p2p2
15
15 Convex Hull – p 1 p 2 p 3 p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Stack p0p0 p1p1 p2p2 p 1 p 2 p 3 is a right turn. Pop p 2, push p 3
16
16 Convex Hull – p 1 p 3 p 4 p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Stack p0p0 p1p1 p3p3 p 1 p 3 p 4 is a left turn. Push p 4
17
17 Convex Hull – p 3 p 4 p 5 p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Stack p0p0 p1p1 p3p3 p4p4 p 3 p 4 p 5 is a right turn. Pop p 4, push p 5
18
18 Convex Hull – p 3 p 5 p 6 p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Stack p0p0 p1p1 p3p3 p5p5 p 3 p 5 p 6 is a left turn. Push p 6
19
19 Convex Hull – p 5 p 6 p 7 p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Stack p0p0 p1p1 p3p3 p5p5 p 5 p 6 p 7 is a left turn. Push p 7 p6p6
20
20 Convex Hull – p 6 p 7 p 8 p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Stack p0p0 p1p1 p3p3 p5p5 p 6 p 7 p 8 is a left turn. Push p 8 p6p6 p7p7
21
21 Convex Hull – p 7 p 8 p 9 p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Stack p0p0 p1p1 p3p3 p5p5 p 7 p 8 p 9 is a right turn. Pop p 8 p6p6 p7p7 p8p8
22
22 Convex Hull – p 6 p 7 p 9 p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Stack p0p0 p1p1 p3p3 p5p5 p 6 p 7 p 9 is a right turn. Pop p 7, push p 9 p6p6 p7p7
23
23 Convex Hull – p 6 p 9 p 10 p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Stack p0p0 p1p1 p3p3 p5p5 p 6 p 9 p 10 is a right turn. Pop p 9, p 6, p 5 and p 6, push p 10 p6p6 p9p9
24
24 Convex Hull – p 3 p 10 p 11 p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Stack p0p0 p1p1 p3p3 p 10 p 3 p 10 p 11 is a left turn. Push p 11
25
25 Convex Hull – p 10 p 11 p 12 p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Stack p0p0 p1p1 p3p3 p 10 p 10 p 11 p 12 is a right turn. Pop p 11, push p 12 p 11
26
26 Convex Hull – Final p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 p 11 p 12 Stack p0p0 p1p1 p3p3 p 10 p 12
27
27 Graham’s Scan – Running Time Computing and sorting the polar angles – O(nlogn) The remaining scan – O(n) Total: O(nlogn)
28
28 Farthest pair problem Given a set of points on the plane, find the two points whose distance from each other is the maximum –It is shown than the farthest points must be on the Convex Hull of the points –The idea is to compute the convex hull in O(nlogn), and then find the pair that is farthest, which can be done in O(n) –So, we have a total running time of O(nlogn)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.