Incremental Computing the convex hull R. Inkulu http://www.iitg.ac.in/rinkulu/ (Convex hull incremental construction) 1 / 10
Convex hull A simple polygon P is convex if for any two points p, q P (chosen from the boundary/interior of P), the line segment pq lies in P. 1 assume that no three points in S are collinear 2 when S is a set of points, no polygon P exists so that it encloses S and P CH; in other words, CH has the smallest area (Convex hull incremental construction) 2 / 10
Convex hull A simple polygon P is convex if for any two points p, q P (chosen from the boundary/interior of P), the line segment pq lies in P. Given a set S of n points 1 in R 2, the convex hull CH of S is the smallest 2 convex polygon containing S. 1 assume that no three points in S are collinear 2 when S is a set of points, no polygon P exists so that it encloses S and P CH; in other words, CH has the smallest area (Convex hull incremental construction) 2 / 10
Observations A subset S S of points, known as vertices of CH(S), define the boundary of CH(S). (Convex hull incremental construction) 3 / 10
Observations A subset S S of points, known as vertices of CH(S), define the boundary of CH(S). The interior angle at every vertex of CH(S) is < π. (Convex hull incremental construction) 3 / 10
Observations A subset S S of points, known as vertices of CH(S), define the boundary of CH(S). The interior angle at every vertex of CH(S) is < π. For any two successive vertices v, v of CH(S), all the points in S {v, v } lie on one side of the line v v. (Convex hull incremental construction) 3 / 10
Observations A subset S S of points, known as vertices of CH(S), define the boundary of CH(S). The interior angle at every vertex of CH(S) is < π. For any two successive vertices v, v of CH(S), all the points in S {v, v } lie on one side of the line v v. Let S be an ordered set of vertices of CH(S) while traversing the boundary of CH(S). With respect to any interior point of CH(S), the angles vertices in S make increase (modulo 2π). (Convex hull incremental construction) 3 / 10
Naive algorithm For every pair of points in S, determine whether they are vertices of CH(S). Find an interior point p of CH(S); sort the vertices in angular order w.r.t. p. (Convex hull incremental construction) 4 / 10
Naive algorithm For every pair of points in S, determine whether they are vertices of CH(S). Find an interior point p of CH(S); sort the vertices in angular order w.r.t. p. takes O(n 3 ) time (Convex hull incremental construction) 4 / 10
Incremental algorithm Let p i+1 be the newly added point. Ignore p i+1 if it lies interior to CH i. Otherwise, insert p i+1 to the boundary of CH i at the appropriate position. (Convex hull incremental construction) 5 / 10
Incremental algorithm Let p i+1 be the newly added point. Ignore p i+1 if it lies interior to CH i. Otherwise, insert p i+1 to the boundary of CH i at the appropriate position. paradigm: while considering input online, maintain the object of interest corresponding to the input considered (Convex hull incremental construction) 5 / 10
Few definitions The convex hull CH(S) running from the leftmost point to the rightmost point when the vertices are listed in clockwise order is termed upper hull of CH(S). The remaining part is termed the lower hull of CH(S). (Convex hull incremental construction) 6 / 10
Upper and lower tangents: definitions h u+1 h u h u 1 CH i h l+1 h l h l 1 p i+1 Let the vertices of CH i be numbered in counterclockwise order, starting with the rightmost. Given a convex hull CH i (defined with n > 3 points) and a point p i+1 exterior to CH i and a vertex h u of CH i, p i+1 h u is said to be the upper tangent to CH i from p i+1 if p i+1 is located rightof( h u+1 h u ) and leftof( h u h u 1 ). (Convex hull incremental construction) 7 / 10
Upper and lower tangents: definitions h u+1 h u h u 1 CH i h l+1 h l h l 1 p i+1 Let the vertices of CH i be numbered in counterclockwise order, starting with the rightmost. Given a convex hull CH i (defined with n > 3 points) and a point p i+1 exterior to CH i and a vertex h u of CH i, p i+1 h u is said to be the upper tangent to CH i from p i+1 if p i+1 is located rightof( h u+1 h u ) and leftof( h u h u 1 ). Analogous definition applies to lower tangent from p i+1 to CH i. (Convex hull incremental construction) 7 / 10
Algorithm 1 h u+1 h u h u 1 CH i h l+1 h l h l 1 p i+1 Let CH i be the convex hull of p 1,...,p i and let p i+1 be the newly added point. Determine whether p i+1 is interior by checking its location w.r.t. every edge of CH(S); if yes, go to next iteration For every convex hull vertex h of CH i, check whether h is an endpoint of an upper tangent from p i+1. The upper hull of CH i+1 is defined by excluding points on the convex hull from h u to rightmost point of CH i in the clockwise order and including p i+1 after h u. (Convex hull incremental construction) 8 / 10
Algorithm 1 h u+1 h u h u 1 CH i h l+1 h l h l 1 p i+1 Let CH i be the convex hull of p 1,...,p i and let p i+1 be the newly added point. Determine whether p i+1 is interior by checking its location w.r.t. every edge of CH(S); if yes, go to next iteration For every convex hull vertex h of CH i, check whether h is an endpoint of an upper tangent from p i+1. The upper hull of CH i+1 is defined by excluding points on the convex hull from h u to rightmost point of CH i in the clockwise order and including p i+1 after h u. takes O(n 2 ) time (after analogously computing lower tangent etc.,) (Convex hull incremental construction) 8 / 10
Algorithm 2: improved h u+1 h u h u 1 h h CH i h l+1 h l h l 1 p i+1 Incrementally add points by their increasing x-coord value. Let CH i be the convex hull of p 1,...,p i and let p i+1 be the newly added point. Find the endpoint h u of upper tangent from p i+1 to CH i by doing binary search over the vertices of the upper hull of CH i. The upper hull of CH i+1 is defined by excluding points on the convex hull from h u to rightmost point of CH i in the clockwise order and including p i+1 after h u. (Convex hull incremental construction) 9 / 10
Algorithm 2: improved h u+1 h u h u 1 h h CH i h l+1 h l h l 1 p i+1 Incrementally add points by their increasing x-coord value. Let CH i be the convex hull of p 1,...,p i and let p i+1 be the newly added point. Find the endpoint h u of upper tangent from p i+1 to CH i by doing binary search over the vertices of the upper hull of CH i. The upper hull of CH i+1 is defined by excluding points on the convex hull from h u to rightmost point of CH i in the clockwise order and including p i+1 after h u. takes O(n lg n) time (after analogously computing lower tangent etc.,) (Convex hull incremental construction) 9 / 10
Algorithm 3: simpler algo but bit involved analysis Incrementally add points by their increasing x-coord value. Let CH i be the convex hull of p 1,...,p i and let p i+1 be the newly added point. While the last two points p, p (ordered) on upper hull of CH i together with p i+1 make right turn at p prune p from CH i and continue till reaching h u The upper hull of CH i+1 is defined by the leftmost vertex of CH i to h u along CH i appended with p i+1 (Convex hull incremental construction) 10 / 10
Algorithm 3: simpler algo but bit involved analysis Incrementally add points by their increasing x-coord value. Let CH i be the convex hull of p 1,...,p i and let p i+1 be the newly added point. While the last two points p, p (ordered) on upper hull of CH i together with p i+1 make right turn at p prune p from CH i and continue till reaching h u The upper hull of CH i+1 is defined by the leftmost vertex of CH i to h u along CH i appended with p i+1 takes O(n lg n) time charging argument: constant amount of work done w.r.t. a point p CH i is being charged to p itself if p is determined to be interior to CHi+1; otherwise, charge the same to p i+1 itself (Convex hull incremental construction) 10 / 10