Computational_Geometry_Lec1.pdf
-
Upload
irrshadhussain272 -
Category
Documents
-
view
8 -
download
0
Transcript of Computational_Geometry_Lec1.pdf
-
Elective III: Computational
Geometry Code: CSEB 604
Pritha Banerjee
1
-
Resources
2
Books:
Computational Geometry : Algorithms and
Applications, Mark De Berg, Marc van Kreveld, Mark
Overmars, Otfried Schwarzkopf, Springer
Computational Geometry in C, Joseph O. Rourke,
Cambridge
Lecture notes of David Mount from the web
-
Convex Hull
Input : a set of points P = {p1, p2, p3pn} on
a plane
Output : CH(P) , Find an unique convex
polygon whose vertices are points from P &
contains all points of P.
CH(P): List the vertices of convex polygon in
clockwise order.
-
Convex Hull: Naive Algo
Elective III : CG
Consider all nC2 line segments and check if rest of
the other n-2 points are to the right of the chosen line segment
-
Convex Hull: Naive Method
Input : P = {p1, p2, p3pn} on a plane
Output : List L ,the vertices of convex polygon in
clockwise order.
1. For all ordered pairs (p,q) PxP ( p q)
2. valid = true; {(p,q) is edge of CH}
3. for all points r P p or q
4. if r lies left of line (p,q) (ordered) , edge (p,q)
is not CH edge, valid = false
5. If valid then add (p,q) to E
6. Construct list L of vertices , sorted in clock wise order
Elective III : CG
-
Naive Algo:Slow Convex Hull All the nC2 line segments => n(n-1) = n
2 n pair of
points
For each pair, check all n-2 (O(n)) points are left/right
(constant time operation)
=> O(n3 )
Last step: edges in E are directed, start from any
edge, put both points in L, take end point, find edge
starting with this in E, put in L..=> n+ n-1 + n-
2=> O(n2 ) { can do O(nlogn) but of no use here)
Total: O(n3 ) + O(n2 ) => O(n3 )
Elective III : CG
-
Incremental algorithm
Take help of Incremental algorithm : std.
design technique
Add points one at a time in the Polygon ,
updating solution after each addition
Construct upper and lower hull and join them
Sort on x coordinate
Take points from left to right constructing
upper hull
Take points right to left to construct lower
hull
-
Graham Scan: Incremental algorithm
Elective III : CG
1
1, 2
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-
Elective III : CG
1
1, 2, 3,
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Graham Scan: Incremental algorithm
1,2,3,
-
Elective III : CG
1
1, 2, 4
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Graham Scan: Incremental algorithm
1, 2, 3, 4
-
Elective III : CG
1
1, 2, 4, 5,
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Graham Scan: Incremental algorithm
1,2,4
1,2,5
-
Elective III : CG
1
1, 2, 5, 6
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Graham Scan: Incremental algorithm
1, 2, 5
1, 2, 5, 6, 7
-
Elective III : CG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Graham Scan: Incremental algorithm
1, 2, 5,6
1, 2, 5, 6, 7
1, 2, 5, 7
-
Elective III : CG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Graham Scan: Incremental algorithm
1, 2, 5, 7
1, 2, 5, 7, 8
1, 2, 5, 8
-
Elective III : CG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Graham Scan: Incremental algorithm
1, 2, 5, 8
1, 2, 5, 8, 9
1, 2, 5, 8, 9, 10
1, 2, 5, 8, 9
1, 2, 5, 8, 10
-
Elective III : CG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Graham Scan: Incremental algorithm
1, 2, 5, 8, 10
1, 2, 5, 10
-
Elective III : CG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Graham Scan: Incremental algorithm
1, 2, 5, 10
1, 2, 5, 10, 11
1, 2, 5, 10, 11
1, 2, 5, 10, 11, 12
1, 2, 5, 10, 11, 12, 13
-
Elective III : CG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Graham Scan: Incremental algorithm
1, 2, 5, 10, 11, 13
-
Elective III : CG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Graham Scan: Incremental algorithm
1, 2, 5, 10, 11, 13
1, 2, 5, 10, 13
1, 2, 5, 10, 13, 14
-
Elective III : CG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Graham Scan: Incremental algorithm
1, 2, 5, 10, 14
1, 2, 5, 10, 14, 15
1, 2, 5, 10, 14, 15 Upper Hull constructed
-
Elective III : CG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Graham Scan: Incremental algorithm
Lower Hull constructed by moving
from right to left in similar fashion
-
Graham Scan: Incremental algorithm
Sort points based on x coordinate: O(n log n)
Append left most points p1, p2 in L_upper
For i = 2 to n
While L_upper contains more than 2 points
Append pi to L_upper if last two points in L_upper and
pi makes right turn at last point of L_upper
Else delete the last point from L_upper
Similarly for Lower Hull L_lower
Start with pn and pn-1 in L_lower
-
Graham Scan: complexity
Complexity:
Sorting : O(n log n)
What data structure we use ? Stack
How many times an element is inserted or
deleted from stack for constructing L_upper?
Only once=> over the for loop : O(n)
Similarly for L_lower
Total : O(n) + O(n log n) => O(n log n)
-
Graham Scan: Proof of correctness
2
3
4
6
7
8
9
10
11
12
13
14
1. Consider p1.. p(i-1) are CH
vertices, adding pi
2. p1.. p(i-1) are hull edges=> all
points lie below the chain
3. When pi is added, this new chain
must be above the old chain
;otherwise, there must be some
point in the slab between p(i-1)
and pi that is violating hull
properties and it does not
represent a correct hull edges
p(i-1)
pi
-
Jarvis March (Gift Wrapping) :
Output Sensitive Algorithm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Start with one of the left-most, right-most, top-most,bottom-most point consider a vertical line through this point Rotate clockwise until it hits a point , that becomes next point in CH
-
Jarvis March (Gift Wrapping) :
Output Sensitive Algorithm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Start with one of the left-most, right-most, top-most,bottom-most point consider a vertical line through this point Rotate clockwise until it hits a point , that becomes next point in CH
-
Jarvis March (Gift Wrapping) :
Output Sensitive Algorithm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Start with one of the left-most, right-most, top-most,bottom-most point consider a vertical line through this point Rotate clockwise until it hits a point , that becomes next point in CH
-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Jarvis March (Gift Wrapping) :
Output Sensitive Algorithm
-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Jarvis March (Gift Wrapping) :
Output Sensitive Algorithm
Complexity : Finding one of the extreme point : O(n) Finds next Hull vertex by rotation=> O(n) There are h hull vertex=> O(hn) Time complexity : O(nh), If h is O(log n) => same as Graham Scan
-
Convex Hull
Input : a set of points P = {p1, p2, p3pn} on
a plane
Output : CH(P) , Find an unique convex
polygon whose vertices are points from P &
contains all points of P.
CH(P): List the vertices of convex polygon in
clockwise order.
-
Given two CH: how to Find
Combined Hull?
-
Resources
32
Books:
Computational Geometry in C, Joseph O. Rourke,
Cambridge, Pages: 91-95, Section 3.8 and Pages: 69-
72, Section 3.4
Lecture notes of David Mount from the web, Pages: 14-
17
-
Given two CH: how to Find
Combined Hull?
Find upper and lower tangent for both HA and HB disregarding all other
points lying between lower and upper tangents
HA HB
Upper
tangent
Lower
tangent
-
Given two CH: how to Find
Combined Hull?
Tangent : if p1 and p3 are on the same side
of the tangent line at p2
p2 p1 p3
HA
HB
ab is Lower Tangent: if point (a-1) , (a+1) are on the left
(Orient() is +ve) of segment ab and point (b-1), (b+1) are also on the left
a
a-1 a+1 b
b-1 b+1
ab is Upper Tangent: if point (a-1) , (a+1) are on the right
(Orient() is -ve) of segment ab and point (b-1), (b+1) are also on the right
How to find lower tangent for two hulls: Check all possible pairs? O(n2)
-
Given two CH: how to Find
Combined Hull?
a = right most point of left Hull A
b = left most point of right Hull B
While T = ab is not lower tangent to both A and B
while T not lower tangent to A then a = a-1
while T not lower tangent to B then b = b + 1
Return ab
0 1
2
3
4
HA
HB
0
1
2 3
4
5
6
-
Complexity: finding lower tangent
Finding the leftmost and rightmost point in
HA and HB is : O(n)
Each vertex on the hull vertices are visited
only once: O(n)
-
Convex hull: divide and conquer
Applicable to any dimension
Like merge sort
Sort points P by x coordinate : O(n log n)
CH(S)
If |P| 3, CH(P) is a triangle
Else partition P into 2 sets A ( lowest x
coordinates) and B ( highest x coordinates)
Recursively compute HA= CH(A) , HB= CH(B)
Merge two hulls into CH by computation of upper and lower tangents of HA and HB
-
Time complexity
Sorting : O(n log n)
T(n): time complexity for hull algo
Merge step : O(n)
T(n) = 2T(n/2) + O(n) = O(n log n)
Time complexity is O(n log n)
Elective III : CG