Presentation is loading. Please wait.

Presentation is loading. Please wait.

Polygon overlay in double precision arithmetic One example of why robust geometric code is hard to write Jack Snoeyink & Andrea Mantler Computer Science,

Similar presentations


Presentation on theme: "Polygon overlay in double precision arithmetic One example of why robust geometric code is hard to write Jack Snoeyink & Andrea Mantler Computer Science,"— Presentation transcript:

1

2 Polygon overlay in double precision arithmetic One example of why robust geometric code is hard to write Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

3 Outline n Motivating problems –Clipping, polygon ops, overlay, arrangement –Study precision required by algorithm n Quick summary of algorithms –Test pairs, sweep, topological sweep n A double-precision sweep algorithm –“Spaghetti” segments n Conclusions

4 Three problems in the plane n Polygon clipping (graphics) n Boolean operations (CAD) n Map overlay (GIS)

5 Build red/blue arrangement n Build the arrangement of: n red and n blue line segments in plane, specified by their endpoint coordinates & having no red/red or blue/blue crossings.

6 Why precision is an issue n Algorithms find geometric relationships from coordinate computations. n Efficient algorithms compute only a few relationships and derive the rest.

7 Assumptions & Goal n Assumptions for correctness –Solve the exact problem given by the input –Work for any distribution of the input n Goal: Input+output sensitive algorithm –Demand least precision possible –O(n log n + k) for n segs, k intersections

8 Algorithms to build line segment arrangements n Brute force: test all pairs n Sweep the plane with a line [BO79,C92] n Topological sweep [CE92] n Divide & Conquer [B95] n Trapezoid sweep [C94]

9 Four geometric tests n Orientation/Intersection test n Intersection-in-Slab n Order along line n Order by x coordinate

10 Four geometric tests n Orientation/Intersection test n Intersection-in-Slab n Order along line n Order by x coordinate

11 Four geometric tests n Orientation/Intersection test n Intersection-in-Slab n Order along line n Order by x coordinate

12 Four geometric tests n Orientation/Intersection test n Intersection-in-Slab n Order along line n Order by x coordinate

13 Algorithms to build line segment arrangements n Brute force: test all pairs n Sweep the plane with a line [BO79,C92] n Topological sweep [CE92] n Divide & Conquer [B95]

14 Brute force n Test all pairs for intersection

15 n Sort along lines n Break&rejoin segs Brute force

16 Plane sweep [BO79,C92] n Maintain order along sweep line

17 Plane sweep [BO79,C92] n Maintain order along sweep line

18 Plane sweep [BO79,C92] n Maintain order along sweep line n Know all intersections behind n Next event queue

19 Plane sweep [BO79,C92] n Maintain order along sweep line n Know all intersections behind n Next event queue

20 n Maintain order along sweep line n Know all intersections behind n Next event queue Plane sweep [BO79,C92]

21 n Maintain order along sweep line n Know all intersections behind n Next event queue

22 Plane sweep [BO79,C92] n Maintain order along sweep line n Know all intersections behind n Next event queue

23 Plane sweep [BO79,C92] n Maintain order along sweep line n Know all intersections behind n Next event queue

24 Plane sweep [BO79,C92] n Maintain order along sweep line n Know all intersections behind n Next event queue

25 Topological sweep [CE92] n Maintain order along sweep curve n Know all intersections behind

26 Topological sweep [CE92] n Maintain order along sweep curve n Know all intersections behind n “20 easy pieces”

27 Divide and Conquer [B95] n Find intersections in slab with staircase

28 Divide and Conquer [B95] n Find intersections in slab with staircase n Remove staircase

29 Divide and Conquer [B95] n Find intersections in slab with staircase n Remove staircase n Partition & repeat

30 Degrees of predicates n Orientation/Intersection test (deg. 2) n Intersection-in-Slab (deg. 3) n Order along line (deg. 4) n Order by x coordinate (deg. 5)

31 Degree computations Point p = ( 1,px,py ) = ( (0),(1),(1) ) n Line equation through points p, q:

32 Degree computations Point p = ( 1,px,py ) = ( (0),(1),(1) ) Line equation: (2)W+(1)X+(1)Y n Point at intersection of two lines:

33 Degree computations Point p = ( 1,px,py ) = ( (0),(1),(1) ) Line equation: (2)W+(1)X+(1)Y Point at intersection ( (2),(3),(3) )  Orientation Test: (2)(0)+(1)(1)+(1)(1) = (2)  In Slab: (1) < (3)/(2) or (2)(1) < (3) = (3)  Same Line: (2)(2) + (1)(3) + (1)(3) = (4)  x Order: (3)/(2) < (3)/(2) or (5)<(5) = (5)

34 Degree of algorithms to build line segment arrangements n Brute force (2/4) n Sweep with a line (5) n Topological sweep (4) n Divide & Conquer (3/4) n Trapezoid sweep (3) Restrict to double precision

35 Restricted predicates imply... n Restricted to double precision: –Can’t test where an intersection is –Can’t sort on lines –Can’t sort by x

36 Spaghetti lines n Restricted to double precision: –Can’t test where an intersection is –Can’t sort on lines –Can’t sort by x

37 Spaghetti lines n Restricted to double precision: –Push segments as far right as possible

38 Spaghetti lines n Restricted to double precision: –Push segments as far right as possible –Endpoints witness intersections

39 A sweep for red/blue spaghetti n Maintain order along sweep consistent with pushing intersections to right n Detect an intersection when the sweep passes its witness

40 Data Structures n Sweep line:

41 Data Structures n Sweep line: –Alternate bundles of red and blue segs

42 Data Structures n Sweep line: –Alternate bundles of red and blue segs –Bundles are in doubly-linked list

43 Data Structures n Sweep line: –Alternate bundles of red and blue segs –Bundles are in doubly-linked list –Blue bundles are in a balanced tree

44 Data Structures n Sweep line: –Alternate bundles of red and blue segs –Bundles are in doubly-linked list –Blue bundles are in a balanced tree –Each bundle is a small tree

45 Events n Sweep events –Now only at vertices n Processing

46 Event processing n Sweep events –Now only at vertices n Processing red –Use trees to locate point in blue bundle

47 Event processing n Sweep events –Now only at vertices n Processing red –Use trees to locate point in blue bundle –Use linked list to locate in red

48 Event processing n Sweep events –Now only at vertices n Processing red –Use trees to locate point in blue bundle –Use linked list to locate in red –Split/merge bundles to restore invariant

49 Event processing n Sweep events –Now only at vertices n Processing red –Use trees to locate point in blue bundle –Use linked list to locate in red –Split/merge bundles to restore invariant

50 Event processing n Process blue the same n Time: O(n log n + k) –Tree operations prop to # of vertices –Bundle operations prop to # of intersections –Degeneracies can easily be handled

51 Handling degeneracies n Shared endpoints n Endpoint on a line n Collinear segments

52 Handling degeneracies n Shared endpoints n Endpoint on a line n Collinear segments Introduce vertices, since they are exact

53 Algorithm Summary n We have an optimal algorithm to build an arrangement of red/blue segments, (and only for red/blue segments). n We used only the orientation predicate. n Data structuring is moderate. n Can handle point/line degeneracies: breaking lines at input points is OK.

54 Demo applet www.cs.unc.edu/ ~snoeyink/ demos/ rbseg/

55 A lower bound for spaghetti With only intersection and above/below tests, counting intersections requires Ω(nk ½ ) ops. With convex hulls O(n log 2 n + k) ops suffice for intersections [BS99], but not arrangement. n k½k½

56 Open question n How do we perform geometric rounding to take output back to single precision? –probably dependant on application domain –snap rounding is one idea

57 Fin


Download ppt "Polygon overlay in double precision arithmetic One example of why robust geometric code is hard to write Jack Snoeyink & Andrea Mantler Computer Science,"

Similar presentations


Ads by Google