Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Post on 30-Jan-2016

27 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

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 - PowerPoint PPT Presentation

Transcript

Polygon overlay in double precision

arithmeticOne example of why robust geometric code is hard to

write

Jack Snoeyink & Andrea MantlerComputer 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: 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

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

Test all pairs for intersection Sort along lines Break&rejoin segs

Brute force

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 Next event queue

Plane sweep [BO79,C92]

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

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

Plane sweep [BO79,C92]

Plane sweep [BO79,C92]

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

Plane sweep [BO79,C92]

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

Plane sweep [BO79,C92]

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

Plane sweep [BO79,C92]

Maintain order along sweep line Know all intersections behind Next event 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:

)1()1()2(1

1

1

11

1

YXWqx

pxY

qy

pyX

qyqx

pypxW

YXW

qyqx

pypx

Degree computations

Point p = (1,px,py) = ((0),(1),(1)) Line equation: (2)W+(1)X+(1)Y

Point at intersection of two lines:

)3()3()2()1()2(

)1()2(

)1()2(

)1()2(

)1()1(

)1()1()1()1()2(

)1()1()2(

YXWYXW

YXW

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

Brute force (2/4) Sweep with a line (5) Topological sweep (4) Divide & Conquer (3/4) Trapezoid sweep (3)

Restrict to double precision

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

Handling degeneracies

Shared endpoints

Endpoint on a line

Collinear segments

Introduce vertices, since they are exact

Algorithm Summary

We have an optimal algorithm to build an arrangement of red/blue segments, (and only for red/blue segments).

We used only the orientation predicate. Data structuring is moderate. 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 log2 n + k) ops suffice for intersections [BS99], but not arrangement.

n

Open question

How do we perform geometric rounding to take output back to single precision?

– probably dependant on application domain– snap rounding is one idea

Fin

top related