



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




CS 8803 Computational Geometry Homework 1 Georgia Tech Fall 2004
Zhou, Zhen Hao(Howard) [email protected] Friday, January 23, 2004
First we use the algorithm described in problem 2 to compute the convex hull of P 1 ∪ P 2 in linear time. Then, we check whether P 1 ∪ P 2 is equal to P 1 or P 2 to make sure that one polygon is not inside the other. After that, we determine whether the interior of P 1 and P 2 intersects in O(n) time. By eliminating those special cases, we now have two convex polygons intersecting each other. For each edge in P 1 ∪P 2 that has end points coming from both polygons, we call it the bridge. The two vertex chains under such a bridge constructs a sail polygon. That is, a polygon in which the right chain keeps turning right and the left chain keeps turning left. Observe that such a sail polygon has the property that it can be recursively reduced to a sail polygon with one less vertex by removing the bottom triangle until we reach its tip where the intersection is. It can also be shown that the bridge and the intersection are in one to one correspondence. Hence, we can find an intersection point under each bridge and the total running time for finding all the intersection points is O(n) since we remove each vertex at most once.
First, for each polygon, we construct a sorted list of vertices according to the y coordinate. This can be done in O(n) time in the following way. We find the vertex with the largest y coordi- nate and the one with the minimum y coordinate (O(n)). We then separate the original circular list into two chains which are sorted according to y coordinates, one in ascending order and the other in descending order. We reverse one chain and merge the two chains into one sorted list (O(n)).
Now we have two sorted list of vertices according to their y coordinates. We merge those two lists to come up with a sorted list (O(n)) and apply the Graham Scam algorithm to compute the convex hull for this list of n vertices (O(n)). Therefore, we’ve computed the convex hull of P 1 ∪ P 2 in linear time.
First, find the minimum min and maximum max of these n numbers, this will take O(n) time. Then converting these points to 2D coordinates using the following scheme. For any number x, make a 2D coordinate (x, x) except for the maximum number max. assign max (max, min). Thus will have n such points. We will then perform the 2D convex hull algorithm on these points which takes O(T (n)) time. the convex hull algorithm will return us a circular list of 2D points, and we then find (min, min) and traverse the list until we reach (max, min). The list of x coordinates will be the sorted list of n numbers. Therefore, this algorithm sorts n numbers in O(T (n) + n) time. The above method will produce a degenerate convex polygon (a triangle), there is another algorithm that can avoid this. First, we normalize this list of numbers so that they lie within the interval [0, π 2 ] (O(n)). Then, for each number except for the minimum, we assign a 2D coordinate (x, cos x), and we assign the minimum (0, 0) (O(n)). After performing the 2D convex hull algorithm, we will order the original numbers according to the corresponding vertex list. The running time of this algorithm is also O(T (n) + n).
This algorithm is similar to the 2D line intersection algorithm. We sweep the plane with a rotating ray originating at p (This can be easily achieved by working in a polar coordinate sys- tem). We use two data structures EVENT and STATUS to store the event points and sweeping line status.. The two event types are 1) inserting new interval into STATUS. 2) remove interval from STATUS.
Initially, EVENT keeps the end points of all the intervals and we start sweeping the plane with a ray vertically upward originating at p. When the sweeping ray first touches the end point of an interval (in the case of several intervals, we pick the interval having the end point closest to p.), we pick that interval as the currently visible interval. Since the intervals are disjoint, therefore, we can safely assume that the currently visible interval will not change until one of the following two events happens. 1) an new interval gets inserted into STATUS and is in closer to p than the currently visible curve at the sweeping ray. In this case, we will make the new interval the currently visible curve. 2) The currently visible interval reaches its end point. In this case, we will make its immediate neighbor the currently visible interval (only one possible at this sweeping ray since the current visible interval is the closest to p). Thus, since we process each end point exactly once in the entire algorithm, and all the operation cost O(log n) time, the total running time will be O(n log n).
The algorithm will be similar to the 2D line intersection algorithm. We will sweep the plane with a horizontal line. We use two data structures EVENT and STATUS to store the event points and sweeping line status. Notice that the difference here is that we only have horizontal or vertical intervals; therefore, we will never need to swap the vertical lines in STATUS. Thus, we only need two kinds of event: insertion and removal of interval from STATUS, instead of three. Because The vertical intervals do not intersect with each other, hence don’t need to be swapped.
We first sort all the end points and put them in EVENT (O(n log n)). Then, we start the sweeping line from the top and sweep it down. Whenever it encounters the end point of a vertical interval it will do insertion or removal of the interval to STATUS (O(log n)). When it encounters a horizontal interval, it will insert both of its end points into STATUS (O(log n)), and range count the vertical intervals in between (O(log n)), and then we remove those end points from STATUS. At the end, we sum up the count for each horizontal interval and that is the total number of intersection. Since each vertical interval gets inserted once and removed once and each horizontal interval end points will introduce two insertion, two removal and one counting operation, the total running time is (O(n log n) = O(n log n) + nO(log n)).
In order to be able to count the number of elements between two nodes in the 2-3 tree, we can modify our 2-3 tree as following. For each node, during creation, we will keep a count for the total number of descendents it has and update this number with every insertion or removal operation. During range counting, we will update this count as we traverse from the starting node to the ending node, each update takes constant time and the traversal operation takes O(log n) time.