560 likes | 716 Views
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. Outline. Motivating problems Clipping, polygon ops, overlay, arrangement Study precision required by algorithm
E N D
Polygon overlay in double precision arithmeticOne example of why robust geometric code is hard to write Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill
Outline • Motivating problems • Clipping, polygon ops, overlay, arrangement • Study precision required by algorithm • Quick summary of algorithms • Test pairs, sweep, topological sweep • A double-precision sweep algorithm • “Spaghetti” segments • Conclusions
Three problems in the plane • Polygon clipping (graphics) • Boolean operations (CAD) • Map overlay (GIS)
Build red/blue arrangement • Build the arrangement of: nred and nblue line segments in plane, specified by their endpoint coordinates & having no red/red or blue/blue crossings.
Why precision is an issue • Algorithms find geometric relationships from coordinate computations. • Efficient algorithms compute only a few relationships and derive the rest.
Assumptions & Goal • Assumptions for correctness • Solve the exact problem given by the input • Work for any distribution of the input • Goal: Input+output sensitive algorithm • Demand least precision possible • O(n log n + k) for n segs, k intersections
Algorithms to build line segment arrangements • Brute force: test all pairs • Sweep the plane with a line [BO79,C92] • Topological sweep [CE92] • Divide & Conquer [B95] • Trapezoid sweep [C94]
Four geometric tests • Orientation/Intersection test • Intersection-in-Slab • Order along line • Order by x coordinate
Four geometric tests • Orientation/Intersection test • Intersection-in-Slab • Order along line • Order by x coordinate
Four geometric tests • Orientation/Intersection test • Intersection-in-Slab • Order along line • Order by x coordinate
Four geometric tests • Orientation/Intersection test • Intersection-in-Slab • Order along line • Order by x coordinate
Algorithms to build line segment arrangements • Brute force: test all pairs • Sweep the plane with a line [BO79,C92] • Topological sweep [CE92] • Divide & Conquer [B95]
Brute force • Test all pairs for intersection
Brute force • Test all pairs for intersection • Sort along lines • Break&rejoin segs
Plane sweep [BO79,C92] • Maintain order along sweep line
Plane sweep [BO79,C92] • Maintain order along sweep line
Plane sweep [BO79,C92] • Maintain order along sweep line • Know all intersections behind • Nextevent queue
Plane sweep [BO79,C92] • Maintain order along sweep line • Know all intersections behind • Nextevent queue
Plane sweep [BO79,C92] • Maintain order along sweep line • Know all intersections behind • Nextevent queue
Plane sweep [BO79,C92] • Maintain order along sweep line • Know all intersections behind • Nextevent queue
Plane sweep [BO79,C92] • Maintain order along sweep line • Know all intersections behind • Nextevent queue
Plane sweep [BO79,C92] • Maintain order along sweep line • Know all intersections behind • Nextevent queue
Plane sweep [BO79,C92] • Maintain order along sweep line • Know all intersections behind • Nextevent queue
Topological sweep [CE92] • Maintain order along sweep curve • Know all intersections behind
Topological sweep [CE92] • Maintain order along sweep curve • Know all intersections behind • “20 easy pieces”
Divide and Conquer [B95] • Find intersections in slab with staircase
Divide and Conquer [B95] • Find intersections in slab with staircase • Remove staircase
Divide and Conquer [B95] • Find intersections in slab with staircase • Remove staircase • Partition & repeat
Degrees of predicates • Orientation/Intersection test (deg. 2) • Intersection-in-Slab (deg. 3) • Order along line (deg. 4) • Order by x coordinate (deg. 5)
Degree computations • Point p = (1,px,py) = ((0),(1),(1)) • Line equation through points p, q:
Degree computations • Point p = (1,px,py) = ((0),(1),(1)) • Line equation: (2)W+(1)X+(1)Y • Point at intersection of two lines:
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)
Restrict to double precision Degree of algorithms to build line segment arrangements • Brute force (2/4) • Sweep with a line (5) • Topological sweep (4) • Divide & Conquer (3/4) • Trapezoid sweep (3)
Restricted predicates imply... • Restricted to double precision: • Can’t test where an intersection is • Can’t sort on lines • Can’t sort by x
Spaghetti lines • Restricted to double precision: • Can’t test where an intersection is • Can’t sort on lines • Can’t sort by x
Spaghetti lines • Restricted to double precision: • Push segments as far right as possible
Spaghetti lines • Restricted to double precision: • Push segments as far right as possible • Endpoints witness intersections
A sweep for red/blue spaghetti • Maintain order along sweep consistent with pushing intersections to right • Detect an intersection when the sweep passes its witness
Data Structures • Sweep line:
Data Structures • Sweep line: • Alternate bundles of red and blue segs
Data Structures • Sweep line: • Alternate bundles of red and blue segs • Bundles are in doubly-linked list
Data Structures • Sweep line: • Alternate bundles of red and blue segs • Bundles are in doubly-linked list • Blue bundles are in a balanced tree
Data Structures • 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
Events • Sweep events • Now only at vertices • Processing
Event processing • Sweep events • Now only at vertices • Processing red • Use trees to locate point in blue bundle
Event processing • Sweep events • Now only at vertices • Processing red • Use trees to locate point in blue bundle • Use linked list to locate in red
Event processing • Sweep events • Now only at vertices • Processing red • Use trees to locate point in blue bundle • Use linked list to locate in red • Split/merge bundles to restore invariant
Event processing • Sweep events • Now only at vertices • Processing red • Use trees to locate point in blue bundle • Use linked list to locate in red • Split/merge bundles to restore invariant
Event processing • Process blue the same • Time: O(n log n + k) • Tree operations prop to # of vertices • Bundle operations prop to # of intersections • Degeneracies can easily be handled
Handling degeneracies • Shared endpoints • Endpoint on a line • Collinear segments