![Page 1: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/1.jpg)
1
Today’s Material
• Computational Geometry Problems– Closest Pair Problem– Convex Hull
• Jarvis’s March, Graham’s scan
– Farthest Point Problem
![Page 2: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/2.jpg)
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?
![Page 3: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/3.jpg)
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
p0
p1
p2
p3p4
p5
p6p7p8
p9
p10
p11p12
![Page 4: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/4.jpg)
4
Convex Hull – Jarvis’s March
p0
p1
p2
p3p4
p5
p6p7p8
p9
p10
p11p12
• Take the horizontal line going through p0, 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 p1
![Page 5: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/5.jpg)
5
Convex Hull – Jarvis’s March
p0
p1
p2
p3p4
p5
p6p7p8
p9
p10
p11p12
• Continue gift-wrapping from p1. Next point is p3
![Page 6: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/6.jpg)
6
Convex Hull – Jarvis’s March
p0
p1
p2
p3p4
p5
p6p7p8
p9
p10
p11p12
• Continue gift-wrapping from p3. Next point is p10
![Page 7: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/7.jpg)
7
Convex Hull – Jarvis’s March
p0
p1
p2
p3p4
p5
p6p7p8
p9
p10
p11p12
• Continue gift-wrapping from p10. Next point is p12
![Page 8: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/8.jpg)
8
Convex Hull – Jarvis’s March
p0
p1
p2
p3p4
p5
p6p7p8
p9
p10
p11p12
• Continue gift-wrapping from p12. Next point is p0
![Page 9: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/9.jpg)
9
Convex Hull – Jarvis’s March
p0
p1
p2
p3p4
p5
p6p7p8
p9
p10
p11p12
• Continue gift-wrapping from p12. Next point is p0. We are done now.
![Page 10: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/10.jpg)
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(n2)– Can we make sure that the running time is
always O(nlogn)?• Graham’s scan
![Page 11: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/11.jpg)
11
Graham’s Scan• Let p0 be the point in Q with the min y-coordinate or the leftmost such point in the case of a
tie
• Let <p1, p2, .., pm> be the remaining points in Q sorted by polar angle in counter-clockwise order around p0. If more than one point has the same angle, remove all but the one that is farthest from p0
p0
p1
p2
p3
p4
p5
p6p7p8
p9
p10
p11p12
![Page 12: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/12.jpg)
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
![Page 13: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/13.jpg)
13
Graham’s Scan - Algorithm Push(p0, S);
Push(p1, S);
Push(p2, S);
for i=3 to m do while the angle formed by points NEXT_TO_TOP(S), TOP(S) and pi
makes a non-left turn do Pop(S);
endwhile Push(pi, S);
endfor
return S;
![Page 14: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/14.jpg)
14
Convex Hull – Initial State
p0
p1
p2
p3
p4
p5
p6p7p8
p9
p10
p11p12
Stack
p0
p1
p2
![Page 15: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/15.jpg)
15
Convex Hull – p1p2p3
p0
p1
p2
p3
p4
p5
p6p7p8
p9
p10
p11p12
Stack
p0
p1
p2
p1p2p3 is a right turn. Pop p2, push p3
![Page 16: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/16.jpg)
16
Convex Hull – p1p3p4
p0
p1
p2
p3p4
p5
p6p7p8
p9
p10
p11p12
Stack
p0
p1
p3
p1p3p4 is a left turn. Push p4
![Page 17: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/17.jpg)
17
Convex Hull – p3p4p5
p0
p1
p2
p3p4
p5
p6p7p8
p9
p10
p11p12
Stack
p0
p1
p3
p4
p3p4p5 is a right turn. Pop p4, push p5
![Page 18: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/18.jpg)
18
Convex Hull – p3p5p6
p0
p1
p2
p3p4
p5
p6p7p8
p9
p10
p11p12
Stack
p0
p1
p3
p5
p3p5p6 is a left turn. Push p6
![Page 19: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/19.jpg)
19
Convex Hull – p5p6p7
p0
p1
p2
p3p4
p5
p6p7p8
p9
p10
p11p12
Stack
p0
p1
p3
p5
p5p6p7 is a left turn. Push p7
p6
![Page 20: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/20.jpg)
20
Convex Hull – p6p7p8
p0
p1
p2
p3p4
p5
p6p7p8
p9
p10
p11p12
Stack
p0
p1
p3
p5
p6p7p8 is a left turn. Push p8
p6
p7
![Page 21: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/21.jpg)
21
Convex Hull – p7p8p9
p0
p1
p2
p3p4
p5
p6p7
p8
p9
p10
p11p12
Stack
p0
p1
p3
p5
p7p8p9 is a right turn. Pop p8
p6
p7
p8
![Page 22: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/22.jpg)
22
Convex Hull – p6p7p9
p0
p1
p2
p3p4
p5
p6p7
p8
p9
p10
p11p12
Stack
p0
p1
p3
p5
p6p7p9 is a right turn. Pop p7, push p9
p6
p7
![Page 23: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/23.jpg)
23
Convex Hull – p6p9p10
p0
p1
p2
p3p4
p5
p6
p7p8
p9
p10
p11p12
Stack
p0
p1
p3
p5
p6p9p10 is a right turn. Pop p9, p6, p5 and p6, push p10
p6
p9
![Page 24: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/24.jpg)
24
Convex Hull – p3p10p11
p0
p1
p2
p3p4
p5
p6p7p8
p9
p10
p11p12
Stack
p0
p1
p3
p10
p3p10p11 is a left turn. Push p11
![Page 25: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/25.jpg)
25
Convex Hull – p10p11p12
p0
p1
p2
p3p4
p5
p6p7p8
p9
p10
p11p12
Stack
p0
p1
p3
p10
p10p11p12 is a right turn. Pop p11, push p12
p11
![Page 26: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/26.jpg)
26
Convex Hull – Final
p0
p1
p2
p3p4
p5
p6p7p8
p9
p10
p11p12
Stack
p0
p1
p3
p10
p12
![Page 27: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/27.jpg)
27
Graham’s Scan – Running Time• Computing and sorting the polar angles –
O(nlogn)• The remaining scan – O(n)• Total: O(nlogn)
![Page 28: 1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem](https://reader030.vdocuments.site/reader030/viewer/2022032703/56649cf95503460f949c9f62/html5/thumbnails/28.jpg)
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)