Computational Geometry: Line Arrangements

Computational Geometry: Line Arrangements Computational Geometry: Line Arrangements Luis Pe˜ naranda IMPA January 21-25, 2013 Luis Pe˜ naranda | IM...
Author: Osborn Lawson
0 downloads 2 Views 735KB Size
Computational Geometry: Line Arrangements

Computational Geometry: Line Arrangements Luis Pe˜ naranda IMPA

January 21-25, 2013

Luis Pe˜ naranda | IMPA | January 21-25, 2013

1 / 33

Computational Geometry: Line Arrangements

Course Outline

Lectures 1. Line Segment Arrangements in the Plane 2. Robustness in Geometric Computations 3. Arrangements in CGAL

Luis Pe˜ naranda | IMPA | January 21-25, 2013

2 / 33

Computational Geometry: Line Arrangements

Bibliography Bibliography I

M. de Berg, M. van Kreveld, M. Overmars, O. Cheong. Computational Geometry: Algorithms and Applications. 3rd edition, Springer, 2008.

I

F. Preparata and M. Shamos. Computational Geometry: an Introduction. Springer, 1985.

I

H. Edelsbrunner. Algorithms in Combinatorial Geometry. Springer, 1987.

I

J. Goodman and J. O’Rourke, eds. Handbook of Discrete and Computational Geometry. 2nd edition, Chapman & Hall, 2004.

I

J.-D. Boissonnat and M. Teillaud, eds. Effective Computational Geometry for Curves and Surfaces. Springer, 2007.

Luis Pe˜ naranda | IMPA | January 21-25, 2013

3 / 33

Computational Geometry: Line Arrangements

Today’s Lecture

Line Segment Arrangements in the Plane I

Line Segment Intersection

I

The DCEL

I

Overlays

I

Application: Boolean Operations

Luis Pe˜ naranda | IMPA | January 21-25, 2013

4 / 33

Computational Geometry: Line Arrangements

Introduction maps information I

cities

I

rivers

I

railroads

I

regions

I

...

Luis Pe˜ naranda | IMPA | January 21-25, 2013

5 / 33

Computational Geometry: Line Arrangements

Introduction maps information I

cities

I

rivers

I

railroads

I

regions

I

...

the data I

are related

I

are stored independently

I

provide information when overlapped

Luis Pe˜ naranda | IMPA | January 21-25, 2013

5 / 33

Computational Geometry: Line Arrangements

First Approach segment intersection I

a map is a set of n segments

I

find all their intersections

Luis Pe˜ naranda | IMPA | January 21-25, 2013

6 / 33

Computational Geometry: Line Arrangements

First Approach segment intersection I

a map is a set of n segments

I

find all their intersections

in other words I

compute the arrangement of the n segments

Luis Pe˜ naranda | IMPA | January 21-25, 2013

6 / 33

Computational Geometry: Line Arrangements

First Approach segment intersection I

a map is a set of n segments

I

find all their intersections

in other words I

compute the arrangement of the n segments

complexity I

brute force O(n2 )

I

in some cases, Ω(n2 )

I

can we do better?

Luis Pe˜ naranda | IMPA | January 21-25, 2013

6 / 33

Computational Geometry: Line Arrangements

Definitions 1 y-interval

Luis Pe˜ naranda | IMPA | January 21-25, 2013

7 / 33

Computational Geometry: Line Arrangements

Definitions 1 y-interval

sweep line an horizontal line that sweeps the plane, from top to bottom

Luis Pe˜ naranda | IMPA | January 21-25, 2013

7 / 33

Computational Geometry: Line Arrangements

More Definitions

status segments intersected by the sweep line at a given moment

Luis Pe˜ naranda | IMPA | January 21-25, 2013

8 / 33

Computational Geometry: Line Arrangements

More Definitions

status segments intersected by the sweep line at a given moment

event points the points on which an update of the status is required

Luis Pe˜ naranda | IMPA | January 21-25, 2013

8 / 33

Computational Geometry: Line Arrangements

Algorithm Outline Sweep-line Algorithm I

order segments intersecting the sweep from left to right

Luis Pe˜ naranda | IMPA | January 21-25, 2013

9 / 33

Computational Geometry: Line Arrangements

Algorithm Outline Sweep-line Algorithm I

order segments intersecting the sweep from left to right

I

test segments only when they are adjacent

Luis Pe˜ naranda | IMPA | January 21-25, 2013

9 / 33

Computational Geometry: Line Arrangements

Algorithm Outline Sweep-line Algorithm I

order segments intersecting the sweep from left to right

I

test segments only when they are adjacent

I

update the status at each move of the sweep line

Luis Pe˜ naranda | IMPA | January 21-25, 2013

9 / 33

Computational Geometry: Line Arrangements

Algorithm Outline Sweep-line Algorithm I

order segments intersecting the sweep from left to right

I

test segments only when they are adjacent

I

update the status at each move of the sweep line

Invariant All intersection points above the sweep line were computed correctly. Luis Pe˜ naranda | IMPA | January 21-25, 2013

9 / 33

Computational Geometry: Line Arrangements

Correctness Lemma 1 Let si and sj be two non-horizontal segments whose interiors intersect in a single point p, and assume there is no third segment passing through p. Then there is an event point above p where si and sj become adjacent and are tested for intersection.

Luis Pe˜ naranda | IMPA | January 21-25, 2013

10 / 33

Computational Geometry: Line Arrangements

Correctness Lemma 1 Let si and sj be two non-horizontal segments whose interiors intersect in a single point p, and assume there is no third segment passing through p. Then there is an event point above p where si and sj become adjacent and are tested for intersection.

Proof

Luis Pe˜ naranda | IMPA | January 21-25, 2013

10 / 33

Computational Geometry: Line Arrangements

Data structures event queue Q I

operations: remove next and return; insert

I

implementation: balanced BST with event points, ordered w.r.t. ≺

I

all operations in O(log m)

I

sorting of event points

I

why not a heap?

Luis Pe˜ naranda | IMPA | January 21-25, 2013

symbolic perturbation

11 / 33

Computational Geometry: Line Arrangements

Data structures event queue Q I

operations: remove next and return; insert

I

implementation: balanced BST with event points, ordered w.r.t. ≺

I

all operations in O(log m)

I

sorting of event points

I

why not a heap?

symbolic perturbation

status structure T I

operations: insert; delete; find neighbor

I

implementation: balanced BST (because it must always be sorted), leaves are segments intersecting sweep line

I

all operations in O(log n)

Luis Pe˜ naranda | IMPA | January 21-25, 2013

11 / 33

Computational Geometry: Line Arrangements

Bentley-Ottman Algorithm #1

FindIntersections(S) Input: a set S of line segments in the plane Output: the set of intersection points among the segments in S, with for each intersection point the segments that contain it I

initialize an empty event queue Q and insert the segment points into it;

I

initialize an empty status structure T ;

I

while Q is not empty do determine the next event point p; HandleEventPoint(p);

Luis Pe˜ naranda | IMPA | January 21-25, 2013

12 / 33

Computational Geometry: Line Arrangements

Bentley-Ottman Algorithm #2 HandleEventPoint(p) I

U(p) := {segments whose upper endpoint is p} (these segments are stored with the event point p);

I

Search in T the set S(p) of all segments that contain p (they are adjacent in T ).

I

Let L(p) ⊂ S(p) be the set of segments whose lower endpoint is p;

I

C(p) := {segments that contain p in their interior};

I

if L(p) ∪ U(p) ∪ C(p) contains more than one segment then report p as an intersection, and L(p), U(p) and C(p);

I

Delete the segments in L(p) ∪ C(p) from T ;

I

Insert the segments in U(p) ∪ C(p) into T (the order of the segments in T should correspond to the order in which they are intersected by a sweep line just below p);

Luis Pe˜ naranda | IMPA | January 21-25, 2013

13 / 33

Computational Geometry: Line Arrangements

Bentley-Ottman Algorithm #3 HandleEventPoint(p) (continued) I

if U(p) ∪ C(p) = ∅ then Let sl and sr be the neighbors of p in T ; FindNewEvent(sl ,sr ,p); else Let s 0 be the leftmost segment of U(p) ∪ C(p) in T ; Let sl be the left neighbor of s 0 in T ; FindNewEvent(sl ,s 0 ,p); Let s 00 be the rightmost segment of U(p) ∪ C(p) in T ; Let sr be the right neighbor of s 00 in T ; FindNewEvent(s 00 ,sr ,p);

Luis Pe˜ naranda | IMPA | January 21-25, 2013

14 / 33

Computational Geometry: Line Arrangements

Bentley-Ottman Algorithm #4

FindNewEvent(sl ,sr ,p) I

 if sl and sr intersect below the sweep line  or (on it and to the right of the current event point p) and the intersection is not yet present as an event in Q then Insert the intersection point as an event into Q;

Luis Pe˜ naranda | IMPA | January 21-25, 2013

15 / 33

Computational Geometry: Line Arrangements

Performance (exercise) Lemma 2 FindIntersections computes all intersection points and the segments that contain it correctly.

Luis Pe˜ naranda | IMPA | January 21-25, 2013

16 / 33

Computational Geometry: Line Arrangements

Performance (exercise) Lemma 2 FindIntersections computes all intersection points and the segments that contain it correctly.

Lemma 3 The running time of FindIntersections for a set S of n line segments in the plane is O(n log n + I log n), where I is the number of intersection points of segments in S.

Luis Pe˜ naranda | IMPA | January 21-25, 2013

16 / 33

Computational Geometry: Line Arrangements

Performance (exercise) Lemma 2 FindIntersections computes all intersection points and the segments that contain it correctly.

Lemma 3 The running time of FindIntersections for a set S of n line segments in the plane is O(n log n + I log n), where I is the number of intersection points of segments in S.

Lemma 4 FindIntersections runs in O(n) space.

Luis Pe˜ naranda | IMPA | January 21-25, 2013

16 / 33

Computational Geometry: Line Arrangements

DCEL: the Doubly-Connected Edge List Why? I

maps contain subdivisions in regions

I

DCEL is a representation of that

I

it stores incidence relations. . . and whatever you want

Luis Pe˜ naranda | IMPA | January 21-25, 2013

17 / 33

Computational Geometry: Line Arrangements

DCEL: the Doubly-Connected Edge List Why? I

maps contain subdivisions in regions

I

DCEL is a representation of that

I

it stores incidence relations. . . and whatever you want

DCEL permits I

point-location queries

I

visit edges around a vertex

Luis Pe˜ naranda | IMPA | January 21-25, 2013

17 / 33

Computational Geometry: Line Arrangements

DCEL: the Doubly-Connected Edge List Why? I

maps contain subdivisions in regions

I

DCEL is a representation of that

I

it stores incidence relations. . . and whatever you want

DCEL permits I

point-location queries

I

visit edges around a vertex

Complexity of a subdivision Sum of the number of vertices, edges and faces.

Luis Pe˜ naranda | IMPA | January 21-25, 2013

17 / 33

Computational Geometry: Line Arrangements

DCEL Definitions

Half-edges I

twin half-edges

I

origin and destination

Luis Pe˜ naranda | IMPA | January 21-25, 2013

18 / 33

Computational Geometry: Line Arrangements

DCEL Definitions

Half-edges I

twin half-edges

I

origin and destination

Implementation I

vertex table

I

face table

I

half-edge table

Luis Pe˜ naranda | IMPA | January 21-25, 2013

18 / 33

Computational Geometry: Line Arrangements

Stored Data Vertex records I

coordinates of the vertex

I

pointer to an incident edge

Luis Pe˜ naranda | IMPA | January 21-25, 2013

19 / 33

Computational Geometry: Line Arrangements

Stored Data Vertex records I

coordinates of the vertex

I

pointer to an incident edge

Face records I

outer component

I

inner components

Luis Pe˜ naranda | IMPA | January 21-25, 2013

19 / 33

Computational Geometry: Line Arrangements

Stored Data Vertex records I

coordinates of the vertex

I

pointer to an incident edge

Face records I

outer component

I

inner components

Half-edge records I

origin

I

twin

I

incident face

I

previous and next

Luis Pe˜ naranda | IMPA | January 21-25, 2013

19 / 33

Computational Geometry: Line Arrangements

DCEL Example A simple arrangement

Luis Pe˜ naranda | IMPA | January 21-25, 2013

20 / 33

Computational Geometry: Line Arrangements

General Version of the DCEL

Variants I

enough to walk around

I

associate data with vertex, faces and half-edges

I

store less information

I

higher dimensions

Luis Pe˜ naranda | IMPA | January 21-25, 2013

21 / 33

Computational Geometry: Line Arrangements

Overlay of Subdivisions

Luis Pe˜ naranda | IMPA | January 21-25, 2013

22 / 33

Computational Geometry: Line Arrangements

Definition of Overlay Formal The overlay of two subdivisions S1 and S2 is the subdivision O(S1 , S2 ) such that there is a face f in O(S1 , S2 ) if and only if there are faces f1 in S1 and f2 in S2 such that f is a maximal connected subset of f1 ∩ f2 .

Luis Pe˜ naranda | IMPA | January 21-25, 2013

23 / 33

Computational Geometry: Line Arrangements

Definition of Overlay Formal The overlay of two subdivisions S1 and S2 is the subdivision O(S1 , S2 ) such that there is a face f in O(S1 , S2 ) if and only if there are faces f1 in S1 and f2 in S2 such that f is a maximal connected subset of f1 ∩ f2 .

Informal The overlay O(S1 , S2 ) is the subdivision of the plane induced by the edges from S1 and S2 .

Luis Pe˜ naranda | IMPA | January 21-25, 2013

23 / 33

Computational Geometry: Line Arrangements

Definition of Overlay Formal The overlay of two subdivisions S1 and S2 is the subdivision O(S1 , S2 ) such that there is a face f in O(S1 , S2 ) if and only if there are faces f1 in S1 and f2 in S2 such that f is a maximal connected subset of f1 ∩ f2 .

Informal The overlay O(S1 , S2 ) is the subdivision of the plane induced by the edges from S1 and S2 .

I

each face in O(S1 , S2 ) must be labelled with the faces which contain it

I

we can do it with the DCEL’s of S1 and S2

Luis Pe˜ naranda | IMPA | January 21-25, 2013

23 / 33

Computational Geometry: Line Arrangements

How?

Sweep first

Luis Pe˜ naranda | IMPA | January 21-25, 2013

24 / 33

Computational Geometry: Line Arrangements

And Handle intersections

Luis Pe˜ naranda | IMPA | January 21-25, 2013

25 / 33

Computational Geometry: Line Arrangements

And Handle intersections

What is left?

Luis Pe˜ naranda | IMPA | January 21-25, 2013

25 / 33

Computational Geometry: Line Arrangements

Overlay Faces Graph G I

one node for each boundary cycle (inner or outer)

I

one node for the imaginary outer boundary

I

one arc between two cycles iff one of them is the boundary of a hole and the other has a half-edgde immediatly to the left of the leftmost vertex of that hole cycle

I

no half edge to the left the unbounded face

Luis Pe˜ naranda | IMPA | January 21-25, 2013

link the node representing the cycle with

26 / 33

Computational Geometry: Line Arrangements

Overlay Faces Graph G I

one node for each boundary cycle (inner or outer)

I

one node for the imaginary outer boundary

I

one arc between two cycles iff one of them is the boundary of a hole and the other has a half-edgde immediatly to the left of the leftmost vertex of that hole cycle

I

no half edge to the left the unbounded face

link the node representing the cycle with

Lemma Each connected component of the graph G corresponds exactly to the set of cycles incident to one face.

Luis Pe˜ naranda | IMPA | January 21-25, 2013

26 / 33

Computational Geometry: Line Arrangements

Example of Graph

Luis Pe˜ naranda | IMPA | January 21-25, 2013

27 / 33

Computational Geometry: Line Arrangements

Overlay Algorithm #1 MapOverlay(S1 ,S2 ) Input: subdivisions S1 and S2 , stored in DCEL’s Output: their overlay, stored in a DCEL D I

copy DCEL’s from S1 and S2 to a new DCEL D;

I

compute all intersections between edges from S1 and S2 with the plane sweep algorithm. In addition to the actions on T and Q, do the following: I I

Update D if the event involves edges of both S1 and S2 ; store the half-edge immediately to the left of the event point at the vertex in D representing it;

(now D is the DCEL for O(S1 , S2 ), except that the information about the faces has not been computed yet) I

determine the boundary cycles in O(S1 , S2 ) by traversing D;

Luis Pe˜ naranda | IMPA | January 21-25, 2013

28 / 33

Computational Geometry: Line Arrangements

Overlay Algorithm #2 MapOverlay(S1 ,S2 ) (continued) I

construct the graph G whose nodes correspond to boundary cycles and whose arcs connect each hole cycle to the cycle to the left of its leftmost vertex; and compute its connected components;

I

for each connected component in G do let C be the unique outer boundary cycle in the component; let f denote the face bounded by the cycle; create a face record for f; OuterComponent(f) := some half-edge of C; InnerComponents(f) := {pointers to one half-edge in each hole cycle in the component}; let the IncidentFace() pointers of all half-edges in the cycles point to the face record of f;

I

label each face of O(S1 , S2 ) with the names of the faces of S1 and S2 containing it;

Luis Pe˜ naranda | IMPA | January 21-25, 2013

29 / 33

Computational Geometry: Line Arrangements

Complexity of the overlay algorithm

Theorem Let S1 be a planar subdivision of complexity n1 , let S2 be a subdivision of complexity n2 , and let n = n1 + n2 . The overlay of S1 and S2 can be constructed in O(n log n + k log n) time, where k is the complexity of the overlay.

Luis Pe˜ naranda | IMPA | January 21-25, 2013

30 / 33

Computational Geometry: Line Arrangements

Complexity of the overlay algorithm

Theorem Let S1 be a planar subdivision of complexity n1 , let S2 be a subdivision of complexity n2 , and let n = n1 + n2 . The overlay of S1 and S2 can be constructed in O(n log n + k log n) time, where k is the complexity of the overlay.

Proof Exercise

Luis Pe˜ naranda | IMPA | January 21-25, 2013

30 / 33

Computational Geometry: Line Arrangements

Application: Boolean Operations

Luis Pe˜ naranda | IMPA | January 21-25, 2013

31 / 33

Computational Geometry: Line Arrangements

Boolean Operations

I

a very important application

I

computed as overlays of polygonal regions (can contain holes)

How to compute them I

use the overlay algorithm, but. . .

I

intersection: extract only faces labeled with P1 and P2 ,

I

union: extract P1 or P2 , and

I

difference: extract faces labeled with P1 and not with P2

Luis Pe˜ naranda | IMPA | January 21-25, 2013

32 / 33

Computational Geometry: Line Arrangements

Polygon Operations

Corollary 7 Let P1 be a polygon with n1 vertices and P2 a polygon with n2 vertices, and let n = n1 + n2 . Then P1 ∩ P2 , P1 ∪ P2 and P1 \ P2 can each be computed in O(n log n + k log n) time, where k is the complexity of the output.

Luis Pe˜ naranda | IMPA | January 21-25, 2013

33 / 33

Suggest Documents