Homework Exam 1, Geometric Algorithms, 2016 1. (3 points) Let P be a convex polyhedron in 3-dimensional space. The boundary of P is represented as a DCEL, storing the incidence relationships between the vertices, (half-)edges, and faces in the boundary of P. Assume there are n vertices. There are no vertices of degree 2, and no two adjacent faces are parallel (the description of P is minimal). An xy-silhouette of a convex polyhedron P is defined as a cyclic sequence (cycle) of vertices v 1,..., v k P such that (i) if we remove the third coordinate from each vertex in the sequence, it is a proper description of a convex polygon in the xy-plane, and (ii) for every vertex in the sequence, and for any point on a line segment defined by two consecutive vertices, a line through that vertex or point parallel to the z-axis does not intersect the interior of P. (A proper description of a convex polygon does not include vertices where the interior angle is π, so where the two incident edges are parallel.) Note that two consecutive vertices in the xy-silhouette need not be connected by an edge in P. (a.) (0.5 pnt) An xy-silhouette may not be unique. Explain exactly when the xy-silhouette of a convex polyhedron P is unique and when it is not. Answer: The xy-silhouette is unique if and only if P has no vertical edges (parallel to the z-axis). When there are vertical edges, either the upper endpoint or the lower endpoint can be chosen in the xy-silhouette. If P has a vertical facet but no vertical edges, then the xy-projection of that facet is a line segment and its endpoints are the projections of unique vertices of P, and only these occur in the xy-silhouette. Note that the xy-silhouette is a cyclic sequence of vertices of P and not of the projection of P. Also note that it is cyclic, so a different starting point does not make it a different cyclic sequence. A proof was not asked for. The only essential part of the answer above is the first sentence. (b.) (2 pnt) Give an algorithm that determines an xy-silhouette of a convex polyhedron P in O(n) time, using the standard names of fields of a DCEL (like: IncidentEdge, Next, etc.). The algorithm is passed a single vertex record of some vertex in the boundary of P. As the approach, use a suitable (simple!) traversal of the boundary of P. Write down every constant-time geometric test or operation in words, not in formulas or code. Answer: The approach is to use two phases. In the first, we traverse the boundary of P to find a vertex v with minimum x-coordinate. In the second, we traverse edges and vertices of the boundary of P that have the vertical line property from the definition of xy-silhouette, and extract the xy-silhouette vertices in a cyclic order. Phase 1: Suppose any vertex v of P is given 1. e = IncidentEdge(v) 2. e = Twin(e) 3. while (Next(e )!= e) and (Origin(e ).x >= v.x) 4. do e = Twin(Next(e )) 5. if Origin(e ).x < v.x 6. then v = Origin(e ) and continue at 1. In case there are multiple vertices with the same smallest x-coordinate, we will minimize y-coordinate (lexicographic minimum) as well, and then minimize z-coordinate; this is not in the code above. After phase 1, v is a vertex of P with minimum x-coordinate and phase 2 will start. In the code below, v w represents the direction from the vertex v to the vertex 1
w, and the angle between directions is the (absolute) turn angle required to align the two. It is always π. Phase 2: A vertex v with minimum x-coordinate is given 1. Push v onto a stack S 2. d is the 2D direction of the negative y-axis 3. u = v 4. repeat 5. e = IncidentEdge(v) 6. e = Twin(e) 7. w = Origin(e ) 8. while (Next(e )!= e) 9. do if the xy-projected angle between d and v Origin(Twin(Next(e ))) is smaller than the xy-projected angle between d and v w [ with equality, take the one with lower z-coordinate ] 10. then w = Origin(Twin(Next(e ))); e = Twin(Next(e )) 11. push w onto S 12. while S has at least 3 elements and the last 3 do not make a turn 13. do remove the middle one of them 14. if (w == u) then pop S and return S 15. let d = v w and v = w 15. until False (c.) (0.5 pnt) Argue why your algorithm takes linear time. Answer: The first phase of the algorithm visits a vertex (in the role of v) at most once, because we always change to a vertex with a strictly smaller x-coordinate. For each such vertex, we spend time linear in its degree (number of neighbors). The sum of the degrees of all vertices is bounded by two times the number of edges, and since the vertices and edges of P are a planar graph, this is O(n). Hence, the first phase takes O(n) time. The second phase also visits a vertex (in the role of v) at most once, and exactly the same arguments apply to prove linear time for the second phase. 2. (4 points) Given two sets of red and blue line segments in the plane, denoted R and B, with n and m line segments, respectively. All line segments in R B are disjoint. We want to report every red line segment that is blue-surrounded, meaning that directly to the left and to the right of it, during its full y-span, there is some blue line segment. Give a plane sweep algorithm that takes two sets R and B and reports all blue-surrounded red line segments of R. You may assume that all endpoints of R B have different y-coordinates. (a.) (1 pnt) Define the status of your sweep-line algorithm and describe the status structure. Also describe the event list of your algorithm. Answer: The status for a particular position of the sweep-line l is the set of intersected red and blue line segments of R B, sorted from left to right on intersection point with the sweep line. Each red line segment that intersects the sweep-line stores a Boolean value that is True if it is blue-surrounded above the sweep-line, and False otherwise. The status structure T is a balanced binary search tree storing the status in its leaves. The event list is a list storing all events (upper and lower endpoints of the line segments in R B) in sorted order of decreasing y-coordinate. 2
(b.) (0.5 pnt) Give the initialization of your algorithm. Answer: The initialization consists of computing the event list by sorting all endpoints, and making an empty status structure. (c.) (1.5 pnt) Distinguish in the types of events and describe for each type how it is handled. Answer: There are four types of event points, corresponding to the upper and lower endpoints of the red and of the blue line segments. Note that the algorithm may set the Boolean value of a red segment to False when it is False already (this does not influence correctness). Upper red endpoint p of s: Search with p in T. If the segments directly left and/or right are red, set their Boolean to False, and insert s in T with its Boolean set to False. If the segments directly left and right of p are blue, insert s in T with its Boolean set to True. Lower red endpoint p of s: Search with p in T, and delete s. If its Boolean was True, report it. Upper blue endpoint p of s: Insert s in T. Lower blue endpoint p of s: Search for p in T, and delete s. If directly left and directly right of p there are red segments, then set their Booleans to False. If there is a red segment to only one side and the other side does not have any segments, then set the Boolean of the red segment to False. (d.) (1 pnt) Analyze the running of your algorithm, expressed in n and m. Answer: There are n + m line segments and therefore 2n + 2m endpoints. Each endpoint is an event, and therefore the number of events is O(n+m). Sorting these events in initialization costs O((n + m) log(n + m)) time. Each event involves removing it from the event list (in constant time) and otherwise one insertion or deletion in T, and finding up to two neighbor leaves. Each of these operations takes O(log(n + m)) time. So the total time taken by the algorithm is O((n + m) log(n + m)) time. 3. (2 points) Given a simple polygon P that has no vertices with equal y-coordinate, we are interested in the best horizontal cut. A horizontal cut is a horizontal line segment s (nondegenerate, so of non-zero length) whose endpoints lie on the boundary of P and which itself is fully in P (interior or boundary). A cut therefore splits P in one or two pieces locally above the cut, and one or two pieces locally below the cut. A horizontal cut is best if it minimizes the maximum of: (1) the sum of the areas above the cut, and (2) the sum of the areas below the cut, over all possible horizontal cuts. So it is the most area-balanced cut. A best horizontal cut of a simple polygon with n vertices can be computed in O(n log n) time using a plane sweep, but that is not relevant for this assignment. Here we want to prove a geometric property of the best horizontal cut on which an algorithm can be based. Lemma: Given a simple polygon P with no vertices with equal y-coordinate, the best horizontal cut (i) contains a vertex of P, or (ii) it cuts P into pieces with equal area above and below, or (iii) both. 3
(a.) (1.5 pnt) Prove the lemma. Answer: For a contradiction, assume that the best horizontal cut (i) does not contain a vertex, and (ii) does not cut P into two pieces with equal area above and below. This implies that both endpoints of the cut lie in the interiors of two edges of the boundary of P. We know that these edges are not horizontal, because P does not have any horizontal edges (or else it would have two vertices with the same y-coordinate). Furthermore, the cut splits P into only two pieces which are simple polygons. Assume first that the area of the piece above the cut is strictly larger than the area of the piece below the cut. When can move the cut an arbitrarily small amount upward, keeping its endpoints on the same edges, and decrease the area above the cut. Since we can do it by an arbitrarily small amount, we can make sure that the move does not make the area below the cut larger than the area above the cut. Hence, we have found a better solution than the best cut. A contradiction. If the area of the piece below the cut is strictly larger, we are in a symmetric case and we apply exactly the analogous arguments. (b.) (0.5 pnt) Using the vertex types of Chapter 3, what are the possible types of vertex of P on the best horizontal cut, when it does not result in equal area of the two polygon parts? Answer: This can be either a merge vertex or a split vertex, but nothing else. 4. (1 point) Related to the cut in the previous question is the best diagonal of a simple polygon P. There are three main differences: a diagonal must have both endpoints on vertices of P (see the definition of diagonal in Chapter 3 of the book), its interior lies fully in the interior of P, and it need not be horizontal. The similarity is that the best diagonal also minimizes the area of the larger of the two resulting polygons. Describe an algorithm that computes the best diagonal. The most important aspect of your solution is that it is correct. The second-most important aspect is that it is efficient. Analyze the running time of your algorithm. For this question you do not have to give the details of the algorithm and you may ignore all degenerate cases. The answer should be about half a page. Answer: The simple idea is to try every pair of vertices, test if it gives a diagonal, and if so, compute the areas of the two resulting polygons. 1. For all pairs of vertices p, q in P 2. do 3. for all edges e of P 4. do if the closure of e intersects the interior of pq then take the next p, q 5. Compute the areas on both sides of the diagonal using a standard linear-time area computation 6. Keep it if it is the best one so far O(n 2 ) pairs of vertices are tried, first to test if they are a diagonal in linear time (lines 3 4), and if so, then to compute the areas, also in linear time (lines 5 6). Hence, the algorithm runs in O(n 2 ) (O(n) + O(n)) = O(n 3 ) time. This solution gives the 1 point assigned to this question. You can get an additional point if you see that you can perform a rotational sweep around each vertex (like in exercise 2.14 or 3.14). You can then process any vertex in O(n log n) time, 4
leading to an O(n 2 log n) time algorithm. Assume that we sweep clockwise from a vertex v. We must keep the area of the polygon to the left/counterclockwise from the current diagonal (directed away from v), and update this area by computing only the area in between the previous diagonal and the current diagonal. Or, you can perform the rotational sweep only to find as many diagonals from a vertex as possible. This gives O(n) subpolygons. We compute the area of each in O(n) time overall. Using the angular order of these diagonals, it is now easy to compute the areas of the next clockwise diagonal in O(1) time from the previous one, since the areas are cumulative. The resulting running time is the same, because finding the O(n) diagonals from a vertex already takes O(n log n) time. 5