Top Banner
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
56

Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Jan 30, 2016

Download

Documents

eagan

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
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Polygon overlay in double precision

arithmeticOne example of why robust geometric code is hard to

write

Jack Snoeyink & Andrea MantlerComputer Science, UNC Chapel

Hill

Page 2: 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

Page 3: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Three problems in the plane

Polygon clipping (graphics)

Boolean operations (CAD)

Map overlay (GIS)

Page 4: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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.

Page 5: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Why precision is an issue

Algorithms find geometric relationships from coordinate computations.

Efficient algorithms compute only a few relationships and derive the rest.

Page 6: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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

Page 7: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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]

Page 8: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Four geometric tests

Orientation/Intersection test Intersection-in-Slab Order along line Order by x coordinate

Page 9: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Four geometric tests

Orientation/Intersection test Intersection-in-Slab Order along line Order by x coordinate

Page 10: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Four geometric tests

Orientation/Intersection test Intersection-in-Slab Order along line Order by x coordinate

Page 11: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Four geometric tests

Orientation/Intersection test Intersection-in-Slab Order along line Order by x coordinate

Page 12: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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]

Page 13: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Brute force

Test all pairs for intersection

Page 14: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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

Brute force

Page 15: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Plane sweep [BO79,C92]

Maintain order along sweep line

Page 16: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Plane sweep [BO79,C92]

Maintain order along sweep line

Page 17: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Plane sweep [BO79,C92]

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

Page 18: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Plane sweep [BO79,C92]

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

Page 19: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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

Plane sweep [BO79,C92]

Page 20: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Plane sweep [BO79,C92]

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

Page 21: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Plane sweep [BO79,C92]

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

Page 22: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Plane sweep [BO79,C92]

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

Page 23: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Plane sweep [BO79,C92]

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

Page 24: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Topological sweep [CE92]

Maintain order along sweep curve Know all intersections behind

Page 25: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Topological sweep [CE92]

Maintain order along sweep curve Know all intersections behind “20 easy pieces”

Page 26: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Divide and Conquer [B95]

Find intersections in slab with staircase

Page 27: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Divide and Conquer [B95]

Find intersections in slab with staircase Remove staircase

Page 28: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Divide and Conquer [B95]

Find intersections in slab with staircase Remove staircase Partition & repeat

Page 29: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Degrees of predicates

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

Page 30: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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

Page 31: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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

Page 32: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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)

Page 33: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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

Page 34: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Restricted predicates imply...

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

Page 35: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Spaghetti lines

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

Page 36: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Spaghetti lines

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

Page 37: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Spaghetti lines

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

Page 38: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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

Page 39: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Data Structures

Sweep line:

Page 40: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Data Structures

Sweep line: – Alternate bundles of

red and blue segs

Page 41: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Data Structures

Sweep line: – Alternate bundles of

red and blue segs– Bundles are in

doubly-linked list

Page 42: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Data Structures

Sweep line: – Alternate bundles of

red and blue segs– Bundles are in

doubly-linked list– Blue bundles are in a

balanced tree

Page 43: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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

Page 44: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Events

Sweep events– Now only at vertices

Processing

Page 45: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Event processing

Sweep events– Now only at vertices

Processing red – Use trees to locate

point in blue bundle

Page 46: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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

Page 47: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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

Page 48: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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

Page 49: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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

Page 50: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Handling degeneracies

Shared endpoints

Endpoint on a line

Collinear segments

Page 51: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Handling degeneracies

Shared endpoints

Endpoint on a line

Collinear segments

Introduce vertices, since they are exact

Page 52: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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.

Page 53: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Demo applet

www.cs.unc.edu/ ~snoeyink/

demos/rbseg/

Page 54: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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

Page 55: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

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

Page 56: Jack Snoeyink & Andrea Mantler Computer Science, UNC Chapel Hill

Fin