selected computational geometry problems

Upload: ritajit-majumdar

Post on 02-Jun-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 Selected Computational Geometry problems

    1/12

    Computational GeometryAssignment

    Ritajit Majumdar

    Roll: 91/CSE/111006

    June 18, 2014

    Contents

    1 Problem 2 1

    2 Problem 1 4

    2.1 Part a . . . . . . . . . . . . . . . . . . . . . . . . 42.2 Part b . . . . . . . . . . . . . . . . . . . . . . . . 52.3 Part c . . . . . . . . . . . . . . . . . . . . . . . . 6

    3 Problem 3 7

    4 Problem 4 9

    5 Problem 5 10

  • 8/10/2019 Selected Computational Geometry problems

    2/12

    1 Problem 2

    Let S be a set of n disjoint line segments in the plane, and letp be a point

    not on any of the line segments ofS. Determine all line segments ofS that

    p can see, that is, all line segments ofS that contain some pointqso that the

    open segmentpqdoesnt intersect any line segment of S. Give an O(nlogn)time algorithm for this problem that uses a rotating half-line with its endpoint

    atp.

    Solution

    Input: Set S= {S1, S2, . . . , S n} ofn disjoint straight lines, a point P.Output: All line segments Si seen from P.

    Consider a set N ={Si1,Si2} 0 < i n whereSi1 is the start point andSi2 is the end point of the line segment Si. Let us define event pointas thestart and end points of the straight lines. So for n straight lines, there willbe 2nevent points. I shall explain the upper half in the algorithm, the lowerhalf will follow similarly.

    Algorithm:

    1. Draw a horizontal line passing through P. Let the y-value of this linebe yp.

    2. Rotate the half-line counter clock wise in upward direction, stoppingonly at the event points.

    3. Store the event points as they arrive in a queue. Any data structure willbe suitable where the first event point will be processed first. Queueseemed most appropriate.

    1

  • 8/10/2019 Selected Computational Geometry problems

    3/12

    4. Now, arrive at each event point popping them from the queue.

    5. Stop the half line at the first event point. Include the straight line asthe one seen.

    6. Stop at the next point as they are popped. If it is the point of the samestraight line already entered as seen, then proceed without any action.Otherwise, check the y-value with the y-value of the previous point. Ifthe y-value is less than the previous one, mark the straight line as seen.Otherwise, store the straight line.N.B. This will work because no lines intersect. y-value more means thestraight line is above the current one and cant be seen, at least tillnow.

    7. Check for the stored stright line. Suppose we reach the end point ofone straight line without entering any other line. Now if the next eventpoint belongs to the stored straight line, mark it as seen. Otherwise, ifthe x-value of the next starting point is less than the end point of thestored line, then also mark it as seen.N.B. This is because, since there is no overlapping of lines, there is agap between two lines. So the stored line will be visible from that gap.A condition has been shown in the diagram.

    8. Continue this process for all points above the half-line.

    9. For the lines below the half-line, start from right and continue clockwise downward.

    2

  • 8/10/2019 Selected Computational Geometry problems

    4/12

    The time complexity of this algorithm -

    The inital sorting takes O(nlogn) time.Now for each line, there are 2 event points. So for nstraight lines, there willbe 2n event points, leading to a complexity ofO(n).

    So the final time complexity is - O(nlogn) +O(n) = O(nlogn).

    3

  • 8/10/2019 Selected Computational Geometry problems

    5/12

    2 Problem 1

    2.1 Part a

    You are given a convex polygon P in the plane having nP sides and an x-monotone polygonal chain Q havingnQsides. Give a bound on the maximumnumber of intersections that might occur between the edges of P and Q?

    Solution

    In the following figure, I have taken nP= 7 and nQ = 8.

    It can be noted that since P is a convex polygon and Q is a x-monotonechain, every edge of Q can intersect at most 2 edges of P. A vertex q is saidto be to the right of another vertex p if qx > px or ifqx = px and qy > py.Here qx and qy refers to the x and y coordinate of q respectively.

    Thus, a side of Q can at most intersect one of the upper edges of P and oneof the lower edges of P. There can be no edges in between since the polygonis convex.

    4

  • 8/10/2019 Selected Computational Geometry problems

    6/12

    So an x-monotone chain having nQnumber of edges will intersect a convexpolygon atmost at 2nQ number of points.

    2.2 Part b

    Given P and Q, two x-monotone polygonal chains, give a bound on themaximum number of intersections that might occur between the edges of Pand Q?

    Solution

    If P and Q has npand nq vertices respectively, then their respective num-ber of edges will be np+ 1 and nq+ 1.

    Now, between two intersection points, there will be atleast one vertex ofeither P and Q. But this vertex is not the first or last vertex of the chainsince on both sides of it, there are intersections. So maximum number ofsuch points is

    5

  • 8/10/2019 Selected Computational Geometry problems

    7/12

    (np+ 1) 2 + (nq+ 1) 2 =np+nq 2

    Thus after the first intersecting point, there may be atmost np+ nq 2intersecting points. So maximum number of intersections is (np+nq2)+1 =np+nq 1

    2.3 Part c

    Given P and Q, two monotone polygonal chains with different directons, givea bound on the maximum number of intersections that might occur betweenthe edges of P and Q.

    Solution

    Consider the following situation

    So the maximum number of intersections is possible when each edge of oneintersects every edge of the other, which gives npnqmaximum intersections.

    6

  • 8/10/2019 Selected Computational Geometry problems

    8/12

    3 Problem 3

    You are given a set of n vertical line segments in the plane. Present anefficient algorithm to determine whether there exists a line that intersects allof these segments. (Hint: O(n) time is possible.) Justify your algorithmscorrectness and derive its running time.

    Solution

    Input: A set S of n vertical lines. S ={S1, S2, , Sn}Output: A straight line l that intersects all the n lines, if one exists.

    It should be noted that the straight line cannot be vertical, then it willnot intersect vertical lines. So we can take the equation of the straight lineto be y = mx+ c. If the line is horizontal, then we will have c = 0 and adefinite value ofmx, giving the equation y= const.

    Moreover, each straight line in set S is denoted by two pairs of points,one start point and one end point, i.e. the ith straight line will be trated as(xi, yi1) and (xi, yi2).

    Algorithm:

    7

  • 8/10/2019 Selected Computational Geometry problems

    9/12

    1. Consider the equation of the required straight line l as y= mx+c.

    2. For i 1 to n do

    3. Find the x-value of the equation of the straight line from set S.

    4. Put the x-value in the equation of linel and find the correspondingy-value.

    5. The y-value may be within the line segment from set s. In thatcase there is an equality, otherwise inequality (y-value is greater or lessthan the maximum and minimum y-values of straight line respectively)accordingly.

    6. For n straight lines, there will be n inequalities (or maybe equalities insome case).

    7. Use Linear Programming (LPP) to solve all the n inequalities. Theresult will be any value chosen from the common region. If no commonregion exists, then such a straight line does not exist that intersect alln lines.

    For every one of the n-lines, we need to compute once. The only com-putation for each line is finding the y-value of l from the x-value of theline. So for n lines, the time complexity is O(n). Moreover, solving LPP forn inequalities can be done in O(n) time. So the total time complexity is O(n).

    Finally, since LPP always provides the correct region of intersection, thealgorithm in correct. We can choose any y and x value fro the intersectingline l fromt that common region. This approach will also point out whethersuch a line exists. No region of intersection for all n lines means such linedoes not exist.

    8

  • 8/10/2019 Selected Computational Geometry problems

    10/12

    4 Problem 4

    A simple polygon P is star-shaped if there is a point q in the interior of Psuch that for each pointp on the boundary of P, the open line segment qpliesentirely within the interior of P. Suppose that P is given as a counterclockwisesequence of its vertices v1, v2, . . . , v n. Show that it is possible to determinewhether P is star-shaped in O(n) time (Note: You are not given the pointq.). Prove the correctness of your algorithm.

    Solution

    For every edge ei, draw the corresponding half plane hi whose boundarylies on the line ei. So for n edges, there will be n half planes h1, h2, . . . , hn.

    Define H=h1 h2 . . . hn.

    IfHis not null, then it can be claimed that the polygon is start shaped.This is because if H is not null, then we can choose a point q Hsuch that

    9

  • 8/10/2019 Selected Computational Geometry problems

    11/12

    it can see every edge. Thus the polygon is start-shaped, otherwise it is not.

    Equation of the lines representing the edges can be found in linear time.Moreover, once the half-planes are constructed, the problem of finding whetherH is null is a problem of linear programming which may be solved in lineartime.

    So total time complexity is O(n).

    10

  • 8/10/2019 Selected Computational Geometry problems

    12/12

    5 Problem 5

    The code for the problem has been attached with the mail. A test case andthe corresponding output is also given along with it.

    11