Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithm 1. (Convex Hull) - Pseudo code - Input. A set of points in the plane. Output. A list containing the vertices of Conv ( P). 1. Sort the points.

Similar presentations


Presentation on theme: "Algorithm 1. (Convex Hull) - Pseudo code - Input. A set of points in the plane. Output. A list containing the vertices of Conv ( P). 1. Sort the points."— Presentation transcript:

1 Algorithm 1. (Convex Hull) - Pseudo code - Input. A set of points in the plane. Output. A list containing the vertices of Conv ( P). 1. Sort the points by (x,y)-coordinate, resulting in a sequence p 1,p 2, …,p n. 2. Put the points p 1 and p 2 in the list L upper with p 1 in the first position. 3. For i  3 to n 4. do Append p i to L upper 5. while L upper contains more than two points and the last three points in L upper do not make a right turn 6. do delete the middle of the last three points from L upper. 7-11 the same in the opposite direction: p n to p 1: Make L lower 12. Remove the first and the last point from L upper. 13. Append L upper and L lower to make L. 14. return L.

2 Algorithm 1, Step 5: pipi pipi X X X pipi X X X pipi

3 Left – Right decision Degeneracy O, O,  The complexity of Algorithm 1 is O(nlogn) Exercise 8= Implementation of Algorithm 1 XPiXPi YPiYPi X P i-2 Y P i-2 X P i-1 Y P i-1 1 1 1 > = < 0 XPiXPi X P i-2 X P i-1 = - XPiXPi - Y P i-2 - YPiYPi YPiYPi Y P i-1 - Algorithm 1 (cont.)

4 Algorithm2. (2-dim) Assumption. The points are ordered in a sequence increasingly with respect to the x coordinate. The vertices having the same x coordinate are ordered with respect to the y coordinate middle ones omitted. The algorithm is incremental (inductive), at the step k+1 the (k+1) st point A k+1, as well as the convex hull of the previous points, are used to produce the convex hull C k of the first k+1-points. (Exercise 9 = Implementation of algorithm 2)

5 Storing data. -Edges (oriented): origin and the pointer to the “next” edge. -Vertices: a point A and the edge AB originated at A. Algorithm2. (2-dim) Step k+1. 1. Find the the two vertices of C k which divide the “visible” and the “invisible” part of C k with respect to (“from”) the point A k+1.

6 B0B0 B1B1 BrBr B -s A k+1 [A k+1 B m-1, A k+1 B m ] = B m-1x - A k+1x B m-1y - A k+1y B m x - A k+1x B m y - A k+1y Algorithm2. (2-dim), Step k+1(cont.)

7 Denote B 0 =A k (A k is the vertex prior to A k+1 ). The vertices B m are obtained recursively so that B m-1 B m is the oriented edge of C k and that the 2X2 determinant [A k+1 B m-1, A k+1 B m ] is not positive. In another words, the vertices B m are in the visible part of C k. Let B r be the last one in the sequence having negative determinant, i.e. such that the determinant corresponding to B r and the next vertex of C k is not negative. Hence, the vertex B r is one of the two vertices we are looking for. Similarly, starting with B 0 we can inductively obtain a sequence of the vertices B m-1 with negative indices having the same property. Let B -s be the last vertex in this sequence. Algorithm2. (2-dim), Step k+1(cont.)

8 2. Vertices B -s + 1,…, B r - 1 are deleted together with the corresponding edges. Vertex A k+1 is added together with the edges B -s A k+1 and A k+1 B r. B r B -s A k+1 B r+1 Algorithm2. (2-dim), Step k+1(cont.) B -s A k+1 B r+1 B r

9 3. If there is the vertex B -s -1 i.e if B -s -1, B -s and A k+1 are collinear, the middle point B -s is omitted and the edges B -s -1 B -s and B -s A k+1 are substituted with B -s -1 A k+1.The same procedure is performed with the vertex B r.. Algorithm2. (2-dim), Step k+1(cont.)


Download ppt "Algorithm 1. (Convex Hull) - Pseudo code - Input. A set of points in the plane. Output. A list containing the vertices of Conv ( P). 1. Sort the points."

Similar presentations


Ads by Google