1 / 74

Computational Geometry

Computational Geometry. What is Computational Geometry?. Deals with problems involving geometric primitives: points lines polygons. Geometric Primitives. Points a geometric element determined by an ordered set of coordinates 2D: (x,y) 3D: (x,y,z) 4D: (x,y,z,w) …. B. A.

adah
Download Presentation

Computational Geometry

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computational Geometry

  2. What is Computational Geometry? • Deals with problems involving geometric primitives: • points • lines • polygons

  3. Geometric Primitives • Points • a geometric element determined by an ordered set of coordinates • 2D: (x,y) • 3D: (x,y,z) • 4D: (x,y,z,w) • …

  4. B A Geometric Primitives • Line • a set of points satisfying equation • P = t A + (1-t) B Parametric equation • in 2D • y = m x + c Analytic equation • Line segment • closed subset of a line contained between two points a and b which are called end points • P = t A + (1-t) B where 0  t  1 Parametric equation

  5. Geometric Primitives • Polygons • circular sequence (cycle) of points (vertices)and segments (edges)

  6. Segment intersection:Given two segments, do they intersect Simple closed path:given a set of points, find a non-intersecting polygon with vertices on the points. Inclusion in polygon:Is apointinside or outside apolygon ? Some Geometric Problems

  7. Segment Intersection • Test whether segments (a,b) and (c,d) intersect. How do we do it? a d c b • We could start by writing down the equations of the lines through the segments, then test whether the lines intersect, then ... • An alternative (and simpler) approach is based in the notion of orientation of an ordered triplet of points in the plane

  8. 2 1 • Counterclockwise 2 • Colinear 1 2 1 Orientation • Clockwise if slope2 > slope1 then counterclockwise else if slope2 < slope1 clockwise else colinear

  9. q q 1 1 q q 2 2 p p 2 2 p p 1 1 Intersection and Orientation (p1,q1,p2), (p1,q1,q2), (p2,q2,p1), (p2,q2,q1) (p1,q1,p2), (p1,q1,q2), (p2,q2,p1), (p2,q2,q1)

  10. q 1 q 2 p 2 (p1,q1,p2), (p1,q1,q2), (p2,q2,p1), (p2,q2,q1) p 1 Intersection and Orientation

  11. q 1 q 2 p 2 p 1 Intersection and Orientation • Two segments (p1,q1) and (p2,q2) intersect iff • general case: (p1,q1,p2) and (p1,q1,q2) have different orientations and (p2,q2,p1) and (p2,q2,q1) have different orientations • special case: (p1,q1,p2), (p1,q1,q2), (p2,q2,p1), and (p2,q2,q1) are all collinear and the x-projections of (p1,q1) and (p2,q2) intersect, the y-projections of (p1,q1) and (p2,q2) intersect

  12. q 1 p 1 Intersection and Orientation(special cases) q 2 p 2 q 2 q 1 p 2 (p1,q1,p2), (p1,q1,q2), (p2,q2,p1), (p2,q2,q1) p (p1,q1,p2), (p1,q1,q2), (p2,q2,p1), (p2,q2,q1) 1

  13. y3-y2 x3-x2 y2-y1 x2-x1 How to Compute the Orientation? p3 • slope of segment (p1,p2):  = (y2-y1) / (x2-x1) • slope of segment (p2,p3): = (y3-y2) / (x3-x2) p2 • Orientation test • counterclockwise (left turn): <  • clockwise (right turn):>  • collinear :  =  p1 • The orientation depends on whether the expression (y3-y2)(x2-x1) -(y2-y1)(x3-x2) is positive, negative, or zero.

  14. Point Inclusion • given a polygon and a point • is the point inside ? or • outside the polygon?

  15. a b c e f Point Inclusion • Draw a horizontal line to the right of each point and extend it to infinity • Count the number of times a line intersects the polygon. -even number  point is outside -odd number  point is inside

  16. Point Inclusion • Draw a horizontal line to the right of each point and extend it to infinity • Count the number of times a line intersects the polygon. -even number  point is outside -odd number  point is inside a b c d e f g What about points d and g ?? Special Case !

  17. Segment-Segment Intersection

  18. Segment-Segment Intersection Problem Definition: Let n: #of input segments in a plane Find all intersection points among segments. How many intersections k, possible?

  19. Brute Force Intersect Algorithm Algorithm: Brute Force Intersect(S) Test all pairs (si, sj), i j. If si intersects sj, report si intersects sj. Complexity -Independent of the number of intersections.

  20. Goal Spend time depending on the # of intersection ? • Idea: • Avoid testing all pairs. • Do not Intersect if they are “far apart”.

  21. a2 b1 b b2 a a1 Sweep-line Sweep line ab Status Event Points a b a a b a a1 b1 b2 a2 b1 b2 a2 ab b2 a2 b2 a2 a2

  22. Plane Sweeping Algorithm • Sweep the L over the plane stopping at events. • Three types of events • The left end point is reached • The right end point is reached • An intersection point is reached

  23. Plane Sweeping Algorithm • Sweep the L over the plane stopping at events. • Three types of events • The left end point is reached Insert segment • The right end point is reached Remove segment • An intersection point is reached Switch adjacent segments

  24. b d c e a Plane Sweeping Algorithm

  25. Plane Sweep Algorithm • Analysis • Total # of events = 2 n + k • Event is inserted once and deleted once from event queue Q • Cost of maintaining Q = O((n+k) log(n+k)) • k is at most n2. • So cost of maintaining Q = O((n+k) log n) • Cost of maintaining segment list is O(n log n)

  26. Plane Sweep Algorithm • Analysis (contd.) • Total cost of maintaining Q = O((n+k) log n) • Cost of maintaining segment list: • n segments inserted and deleted at O(log n) cost each. • At every event there are at most 2 new segment adjacencies. • Total intersection calls: O(n+k). • Thus total cost of maintaining segment list: O(n log n) • Total overall cost: O((n+k) log n)

  27. Simple Closed Path Problem:Given a set of points ... “Connect the dots” without crossings

  28. a Simple Closed Path 1. Pick the bottom most point as the anchor point 2. For each point p, compute the angle(p) of the segment (a,p) with respect to the x-axis:

  29. Simple Closed Path • Traverse the points by increasing angle a

  30. Simple Closed Path How do we compute angles? • Option 1: use trigonometry (e.g., tan-1). • the computation is inefficient since trigonometric functions are not in the normal instruction set of a computer and need a call to a math-library routine. a

  31. Simple Closed Path How do we compute angles? • Observation: • we don’t care about the actual values of the angles. We just want to sort by angle. • Option 2 : use orientation to compare angles without actually computing them!! a

  32. p q a Simple Closed Path • Orientation to sort by angles ? • angle(p) < angle(q)  orientation of (a,p,q) is counterclockwise • We obtain an O(n log n)-time algorithm for the simple closed path problem on n points

  33. Convex Hull

  34. Convex Polygon • A convex polygon is a nonintersecting polygon whose internal angles are all convex (i.e., less than 180º) • In a convex polygon, a segment joining two vertices of the polygon lies entirely inside the polygon convex nonconvex

  35. Convex Hull • Definition: The convex hull of a set of points is the smallest convex polygon containing the points • Think of a rubber band snapping around the points

  36. Special Cases • The convex hull is a segment • All the points are collinear • The convex hull is a point • All the points are coincident

  37. Applications • Motion planning • Find an optimal route that avoids obstacles for a robot • Geometric algorithms • Convex hull is like a two-dimensional sorting obstacle start end

  38. The Package Wrapping Algorithm Idea: Think of wrapping a package. Put the paper in contact with the package and continue to wrap around from one surface to the next until you get all the way around.

  39. q p Package Wrap • Question: Given the current point, how do we compute the next point to be wrapped? • Set up an orientation tournament using the current point as the anchor-point. • The next point is selected as the point that beats all other points at CCWorientation, i.e., for any other point, we have orientation(c, p, q) = CCW c

  40. Time Complexity of Package Wrap • For every point on the hull we examine all the other points to determine the next point • Notation: N:number of points M: number of hull points (MN) • Time complexity: (MN) • Worst case: (N2) (All the points are on the hull, and thusM = N) • Average case: (N log N ) — (N4/3) for points randomly distributed inside a square, M = (log N) on average for points randomly distributed inside a circle, M = (N1/3) on average

  41. Computing the Convex Hull • The following method computes the convex hull of a set of points Phase 1: Find the lowest point (anchor point) Phase 2: Form a nonintersecting polygon by sorting the points counterclockwise around the anchor point Phase 3: While the polygon has a nonconvex vertex, remove it

  42. Removing Nonconvex Vertices • Testing whether a vertex is convex can be done using the orientation function • Let p, q and r be three consecutive vertices of a polygon, in counterclockwise order • qconvexorientation(p, q, r) = CCW • qnonconvex orientation(p, q, r) = CW or COLL r r q q p p

  43. The Graham scan is a systematic procedure for removing nonconvex vertices from a polygon The polygon is traversed counterclockwise and a sequence H of vertices is maintained for each vertex r of the polygon Let q and p be the last and second last vertex of H whileorientation(p, q, r) = CW or COLLremove q from Hq pp vertex preceding p in H Add r to the end of H r r p r q p q p q H H H Graham Scan

  44. Analysis • Computing the convex hull of a set of points takes O(n log n) time • Finding the anchor point takes O(n) time • Sorting the points counterclockwise around the anchor point takes O(n log n) time • Use the orientation comparator and any sorting algorithm that runs in O(n log n) time (e.g., heap-sort or merge-sort) • The Graham scan takes O(n) time • Each point is inserted once in sequence H • Each vertex is removed at most once from sequence H

  45. Quick Hull Algorithm

  46. H B M F G D I E C Quick Hull Example J O K P A L N [A B C D E F G H I J K L M N O P]

  47. H B M F G D I E C Quick Hull Example J O K P A L N [A B C D E F G H I J K L M N O P]

  48. H B M F G D I E C Quick Hull Example J O K P A L N [ A B D F G H J K M O P]

  49. H B M F G D I E C Quick Hull Example - Maximum J O K P A L N [A B D F G H J K M O P]

  50. H B M F G D I E C Quick Hull Example - Filter J O K P A L N [[A B F J ] [J O P]]

More Related