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

## 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:

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 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

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

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.

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.

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

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]

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

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

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

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

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]

Brute force n Test all pairs for intersection

n Sort along lines n Break&rejoin segs Brute force

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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)

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

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:

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)

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

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

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

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

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

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

Data Structures n Sweep line:

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

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

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

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

Events n Sweep events –Now only at vertices n Processing

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

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

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

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

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

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

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

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.

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

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½

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

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