41
TU/ e computational geometry introduction Mark de Berg

TU/e computational geometry introduction Mark de Berg

  • View
    217

  • Download
    0

Embed Size (px)

Citation preview

Page 1: TU/e computational geometry introduction Mark de Berg

TU/e

computational geometry introduction

Mark de Berg

Page 2: TU/e computational geometry introduction Mark de Berg

TU/e

IPA Basic Course—Algorithms

introduction• what is CG• applications

randomized incremental construction• easy example: sorting• a general framework• applications to geometric problems

and more …

Page 3: TU/e computational geometry introduction Mark de Berg

TU/e

Computational Geometry

Computational Geometry:

Area within algorithms research dealing with spatial data (points, lines, polygons, circles, spheres, curves, … )

design of efficient algorithms and data structures for spatial data

elementary operations are assumed to take O(1) time and be available

focus on asymptotic running times of algorithms

computing intersection point of two lines, distance between two points, etc

Page 4: TU/e computational geometry introduction Mark de Berg

TU/e

Map overlay

land usage annual rainfall

overlay

Page 5: TU/e computational geometry introduction Mark de Berg

TU/e

Computational Geometry

example: compute all intersections in a set of line segments

naïve algorithm

for i = 1 to n

for j =i+1 to n

do if si intersects sj

then report intersection

Running time: O(n2)

Can we do better ?

Page 6: TU/e computational geometry introduction Mark de Berg

TU/e

Computational geometry: applications (1)

geographic information systems (GIS)

Mississippi delta

MemphisMemphis

MemphisMemphis

ArlingtonArlington

30 cities:

430 = 1018 possibilities

Page 7: TU/e computational geometry introduction Mark de Berg

TU/e

Computational geometry: applications (2)

computer-aided design and manufacturing (CAD/CAM)

3D model of power plant (12.748.510 triangles)

motion planning

virtual walkthroughs

Page 8: TU/e computational geometry introduction Mark de Berg

TU/e

Computational geometry: applications (3)

3D copier

surface reconstruction

3D scanner

3D printer

1

2

34 5 6 7 8

9

Page 9: TU/e computational geometry introduction Mark de Berg

TU/e

Computational geometry: applications (4)

Other applications of surface reconstruction

digitizing cultural heritage

custom-fit products

reverse engineering

Page 10: TU/e computational geometry introduction Mark de Berg

TU/e

Computational geometry: applications (5)

geographic information systems

computer-aided design and manufacturing

robotics and motion planning

computer graphics and virtual reality

databases

structural computational biology

and more …

30 45 age

salary

30.000

50.000

Page 11: TU/e computational geometry introduction Mark de Berg

TU/e

Computational Geometry: algorithmic paradigms

Deterministic algorithms plane sweep geometric divide-and-conquer

Randomized algorithms randomized incremental construction random sampling

today’s focus

Page 12: TU/e computational geometry introduction Mark de Berg

TU/e

EXERCISES

1. Let S be a set of n line segments in the plane. a) Design an algorithm that decides in O (n log n) time if

there are any intersections in S. Hint: Sort the endpoints on y-coordinates, and handle

them in that order in a suitable manner.b) Extend the algorithm so that it reports all intersections in

time O ((n+k) log n), where k is the number of intersections.

For the experts:

Let u (n ) be the maximum number of pairs of points at distance 1 in a set of n points in the plane. Prove that u(n) = Ω (n log n).

Let D be a set of n discs in the plane. Prove that the union complexity of D is O (n ).

Page 13: TU/e computational geometry introduction Mark de Berg

TU/e

Plane-sweep algorithm for line-segment intersection

1

23

45 6

sweep lineinsert segment 1insert segment 2insert segment 3

insert segment 4insert segment 5delete segment 1

When two segments intersect, then there is a horizontal line L such that

the two segments both intersect L

they are neighbors along L

Ordering along L: 1,23,1,23,1,4,23,5,1,4,21 3,5,4,2

Page 14: TU/e computational geometry introduction Mark de Berg

TU/e

Plane sweep

SegmentIntersect

1. Sort the endpoints by y-coordinate. Let p1,…,p2n be the sorted set of endpoints.

2. Initialize empty search tree T.

3. for i = 1 to 2n

4. do { if pi is the left endpoint of a segment s

5. then Insert s into the tree T

6. else Delete s from the tree T

7. Check all pairs of segments that become

neighbors along the sweep line for intersection,

report if there is an intersection. }

Running time ?

Extension to reporting all intersections ?

Page 15: TU/e computational geometry introduction Mark de Berg

TU/e

COFFEE

Page 16: TU/e computational geometry introduction Mark de Berg

TU/e

Lecture II: Randomized incremental construction

ParanoidMax (A)(* A [1..n ] is an array of n numbers *)1. Randomly permute the elements in A2. max := A[1]3. for i := 2 to n4. do if A [i ] > max5. then { max := A[i ]6. for j = 1 to i -1 7. do if A[i ] > max then error }8. return max

Warm-up exercise:

Analyze the worst-case and expected running time of the following algorithm.

Page 17: TU/e computational geometry introduction Mark de Berg

TU/e

Worst-case running time

Worst-case = O(1) + time for lines 2—7

= O(1) + ∑ 2≤i≤n (time for i-th iteration)

= O(1) + ∑ 2≤i≤n ∑ 1≤j≤i-1 O(1)

= O(1) + ∑ 2≤i≤n O(i)

= O(n2)

Page 18: TU/e computational geometry introduction Mark de Berg

TU/e

Expected running time

E [ looptijd ] = O(1) + E [ time for lines 2—7 ]

= O(1) + E [ ∑ 2≤i≤n (time for i-th iteration) ]

= O(1) + ∑ 2≤i≤n E [ time for i-th iteration ]

= O(1) + ∑ 2≤i≤n { Pr [ A[i] ≤ max { A[1..i-1 ] } ] ∙ O(1)

+ Pr [ A[i] > max { A[1..i-1 ] } ] ∙ O(i) }

= O(1) + ∑ 2≤i≤n { 1 ∙ O(1) + (1/i ) ∙ O(i) }

= O(n )

Page 19: TU/e computational geometry introduction Mark de Berg

TU/e

EXERCISE

1. Give an algorithm that puts the elements of a given array A[1..n] into random order. Your algorithm should be such that every possible permutation is equally likely to be the result.

Page 20: TU/e computational geometry introduction Mark de Berg

TU/e

Sorting using Incremental Construction

Input: numbers x1,…,xn

Output: partitioning of x-axis into a collection T of empty intervals defined by the input points

x3 x1 x5 x4 x2

A geometric view of sorting

Incremental Construction: “Add” input points one by one,

and maintain partitioning into intervals

x3 x1 x5 x4 x2

Page 21: TU/e computational geometry introduction Mark de Berg

TU/e

Sorting using Incremental Construction

x3 x1 x5 x4 x2

IC-Sort (S)

1. T := { [ -infty : +infty] }

2. for i := 1 to n

3. do { Find interval J in T that contains xi and remove it.

4. Determine new intervals and insert them into T. }

for each point, maintain pointer to interval that contains it

for each interval in T, maintain conflict list of all points inside

list is empty

list: x4, x5

How?

Page 22: TU/e computational geometry introduction Mark de Berg

TU/e

Sorting using Incremental Construction

IC-Sort (S)

1. T := { [ -infty : +infty] }

2. for i := 1 to n

3. do { Find interval J in T that contains xi and remove it.

4. Determine new empty intervals and insert them into T.

5. Split conflict list of J to get the two new conflict lists. }

for each point, maintain pointer to interval that contains it

for each interval in T, maintain conflict list of all points inside

TOTAL TIME: O ( total size of conflict lists of all intervals that ever appear)

WORST-CASE:

Time analysis:

O(n2)

Page 23: TU/e computational geometry introduction Mark de Berg

TU/e

Sorting using Incremental Construction

RIC-Sort (S)

1. Randomly permute input points

2. T := { [ -infty : +infty] }

3. for i := 1 to n

4. do { Find interval J in T that contains xi and remove it.

5. Determine new empty intervals and insert them into T.

6. Split conflict list of J to get the two new conflict lists. }

for each point, maintain pointer to interval that contains it

for each interval in T, maintain conflict list of all points inside

TOTAL TIME: O ( total size of conflict lists of all intervals that are created)

EXPECTED TIME: ??

Time analysis:

Page 24: TU/e computational geometry introduction Mark de Berg

TU/e

An abstract framework for RIC

S = set of n (geometric) objects; the input

C = set of configurations

D: assigns a defining set D(Δ) S to every configuration Δ є C

K: assigns a killing set K(Δ) S to every configuration Δ є C

4-tuple (S, C, D, K) is called a configuration space

configuration Δ є C is active over a subset S’ S if:

D(Δ) S’ and K(Δ) S’ = o

T(S) = active configurations over S; the output

∩∩

∩ ∩ /

Page 25: TU/e computational geometry introduction Mark de Berg

TU/e

Sorting using Incremental Construction

RIC(S)

1. Compute random permutation x1,…xn of input elements

2. T := { active configurations over empty set }

3. for i := 1 to n

4. do { Remove all configurations Δ with xi є K(Δ) from T.

5. Determine new active configurations; insert them into T.

6. Construct conflict lists of new active configurations. }

for each xi, maintain pointers to all configurations Δ such that xi є K(Δ)

for each configuration Δ in T, maintain conflict list of all xi є K(Δ) Theorem: Expected total size of conflict lists of all created configs:

O( ∑ 1≤i≤n (n / i2) ∙ E [ # active configurations in step i ] )

Page 26: TU/e computational geometry introduction Mark de Berg

TU/e

EXERCISE

1. Use the theorem to prove that the running time of the RIC algorithm for sorting runs in O( n log n ) time.

Page 27: TU/e computational geometry introduction Mark de Berg

TU/e

LUNCH

Page 28: TU/e computational geometry introduction Mark de Berg

TU/e

Lecture III

RIC: more applications

Voronoi diagrams and Delaunay triangulations

Page 29: TU/e computational geometry introduction Mark de Berg

TU/e

Principia Philosophiae (R. Descartes, 1644).

Voronoi diagram

The universe according to Descartes

Page 30: TU/e computational geometry introduction Mark de Berg

TU/e

... .

... .

... .

... .

... .

... .

... .

... .

... .

... .

... .

... .

... .

... .

... .

... .

... .

... .

... .

... .

... .

...

..

.. ..

... ... .

.. .

... .

....

..

..

..

..

.

.. .

...

.

.

..

..

..

..

.

.. .

...

.

. .. .......

.. ......

.

.. .......

.. .......

..

... .

...

... .

... .

.. .

... .

. .

... .

... .

...

...

..

.

.. ....

... .

...

. .

... ..

. ... .

... .

.

...

..

.

.. ...

..

.. .

...

..

.. .... .

... .

.

...

..

.

.. ...

.......

...

.. . ...... .. ..

.....

.. ....

... .....

. .

...

..

. ..

.. .

.. .

......

..

... .

. .

.. .

.

..

..

..... .

... .

.

...

... .....

..

.. .

... .

.

..

... ....

....

..

.

..

...

.

.

..... .

.

...

..

... .

... .

... .

... .

. .

... .

... .

...

...

.

.

.. .....

.

...

.

... .

... .

.. .

... .

... .

... .

...

..

... ....

.

....

.

.

..

....

.

.

.

...... .

.

..

.

... .

... .

... .

... .

.

.. .

... .

.

..

... .....

.

..

.

... .

... .

.. .

... .

.. .

... .

.

.

.. ....

.

.

.

..

..

.

.

.... .

.

...

..

...

...

....

.

.

.

.

...

.

...

...

.. .

..

.

....

.

.

..

....

.

.

.

..

.

..

.

... .

... .

... .

... .

.

.. .

... .

.

..

... .....

.

..

.

... .

... .

.. .

... .

.. .

... .

.

.

.. ....

.

.

.

..

..

.

.

.... .

.

...

..

...

...

....

.

.

.

.

...

.

...

...

.. .

..

.

....

.

.

..

....

.

.

.

..

.... .

...

.

.....

....

.. ..

...

..... ..

.. ..

.. .....

. .

.. ...... .. .

. ..

..

.....

...

..

... .... ..

.... .... .... .. ....

1153 1180

11039811098

1127

1098

1108

1163

.. .. .

. .......

.. .... ......... ..

. .

.. .

... .

. .

.

.. ... .

. .

... ..

.

.......

.

.. .. .

. .......

.. .... ......... ..

. .

.. .

... .

. .

.

.. ... .

. .

... ..

.

.......

.

.. ....

.. ... ...

....

.. .

......

.. ...

....

....

... .

...

.

... .

......

. ..

..

...

.

....... .

. .

.. ....

.. ... ...

....

.. .

......

.. ...

....

....

... .

...

.

... .

......

. ..

..

...

.

....... .

. .

. ......

... ...

........

..... ...

.... ....

.... .. ....

Construction of 3D height models (1)

Page 31: TU/e computational geometry introduction Mark de Berg

TU/e

1153 1180

11039811098

1127

1098

1108

1163

height?

Construction of 3D height models (2)

Page 32: TU/e computational geometry introduction Mark de Berg

TU/e

Construction of 3D height models (3)

Better: use interpolation to determine the height

triangulation

983

983

Page 33: TU/e computational geometry introduction Mark de Berg

TU/e

Construction of 3D height models (4)

1153 1180

11039811098

1127

1098

1108

1163

long and thin triangles are bad

try to avoid small angles

What is a good triangulation?

1153 1180

11039811098

1127

1098

1108

1163

Page 34: TU/e computational geometry introduction Mark de Berg

TU/e

Construction of 3D height models (5)

Voronoi diagram

Delaunay triangulation:

triangulation that maximizes the minimum angle !

Page 35: TU/e computational geometry introduction Mark de Berg

TU/e

Voronoi diagrams and Delaunay triangulations

P : n points (sites) in the plane

V(pi ) = Voronoi cell of site pi

= { q є R2 : dist(q,pi ) < dist(q,pj ) for all j ≠i }

Vor(P ) = Voronoi diagram of P = subdivision induced by Voronoi cells

DT(P) = Delaunay triangulation of P = dual graph of Vor(P)

Page 36: TU/e computational geometry introduction Mark de Berg

TU/e

EXERCISES

3. Prove: a triangle pi pj pk is a triangle in DT(P) if and only if its circumcircle C (pi pj pk ) does not contain any other site

4. Prove: number of triangles in DT(P) is at most 2n-5

Hint: Euler’s formula for connected planar graphs: #vertices — #edges + #faces = 2

3. Design and analyze a randomized incremental algorithm to construct DT(P).

Page 37: TU/e computational geometry introduction Mark de Berg

TU/e

COFFEE

Page 38: TU/e computational geometry introduction Mark de Berg

TU/e

RIC – Limitations of the framework

Robot motion planning

What is the region that is reachable for the robot?

Lecture IV: wrap-up

Page 39: TU/e computational geometry introduction Mark de Berg

TU/e

RIC – Limitations of the framework (cont’d)

The single-cell problem:

Compute cell containing the origin

Idea: compute vertical decomposition for the cell using RIC ?!

Page 40: TU/e computational geometry introduction Mark de Berg

TU/e Spatial data structures store geometric data in 2-, 3- or higher dimensional space such that certain queries can be answered efficiently

applications: GIS, graphics and virtual reality, …

Examples:

range searching

nearest-neighbor searching

point location

more computational geometry

Page 41: TU/e computational geometry introduction Mark de Berg

TU/e

plane sweep

parametric search

arrangements

geometric duality, inversion, Plücker coordinates, …

kinetic data structures

core sets

Davenport-Schinzel sequences

and more … and more …