Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II...

29
Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III

Transcript of Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II...

Page 1: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Institut für Kartographie und GeoinformationProf. Dr. Lutz Plümer

Diskrete Mathematik IIVorlesung 6

SS 2001

Segmentschnitt III

Page 2: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

2 2

Übersicht

• Reduktion von 2-dim auf 1-dim• Scan-Line-Verfahren

• Gegenbeispiel

• Nachbarschaft

• Ordnungsrelation „x <‘‘• Scan-Line & dynamische Ordnung• Zusatzfrage: Wann wird der Schnittpunkt S1 erkannt?• Vereinfachende Annahmen• Algorithmus Scan-Line

• Algorithmus (II)• Datenstrukturen für T und S

• Eine Variante des AVL-Baums• für die Haltepunkte ...

Page 3: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

3 3

Reduktion von 2-dim auf 1-dim

• Überlappung der horizontalen Projektionen ist notwendig, aber nicht hinreichend für einen Schnitt

Page 4: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

4 4

Scan-Line-Verfahren

A

BF

C

D

ES1

S3

S2

S4

Page 5: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

5 5

Gegenbeispiel

zu viele Elemente gleichzeitig aktiv O(n2)

Page 6: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

6 6

Nachbarschaft

-Umgebung

A

B

Page 7: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

7 7

Ordnungsrelation „x <‘‘

x x‘

B

A

C

Ax < B

Ax < C

Cx‘ < A

Cx < B

Ax‘ < B

Cx‘ < B

Page 8: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

8 8

Scan-Line & dynamische Ordnung

A

BF

C

D

ES1

S3

S2

S4

Page 9: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

9 9

Scan-Line & dynamische Ordnung

A

BF

C

D

ES1

S3

S2

S4

A

Page 10: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

10 10

Scan-Line & dynamische Ordnung

A

BF

C

D

ES1

S3

S2

S4

AE

Page 11: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

11 11

Scan-Line & dynamische Ordnung

A

BF

C

D

ES1

S3

S2

S4

B

EA

Page 12: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

12 12

Scan-Line & dynamische Ordnung

A

BF

C

D

ES1

S3

S2

S4

B

DA

E

Page 13: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

13 13

Scan-Line & dynamische Ordnung

A

BF

C

D

ES1

S3

S2

S4

B

CA

DE

Page 14: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

14 14

Scan-Line & dynamische Ordnung

A

BF

C

D

ES1

S3

S2

S4

B

DC

E

Page 15: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

15 15

Scan-Line & dynamische Ordnung

A

BF

C

D

ES1

S3

S2

S4

B

EC

D

Page 16: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

16 16

Scan-Line & dynamische Ordnung

A

BF

C

D

ES1

S3

S2

S4

F

CB

ED

Page 17: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

17 17

Scan-Line & dynamische Ordnung

A

BF

C

D

ES1

S3

S2

S4

B

CF

ED

Page 18: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

18 18

Scan-Line & dynamische Ordnung

A

BF

C

D

ES1

S3

S2

S4

B

CF

E

Page 19: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

19 19

Scan-Line & dynamische Ordnung

A

BF

C

D

ES1

S3

S2

S4

C

EF

Page 20: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

20 20

Scan-Line & dynamische Ordnung

A

BF

C

D

ES1

S3

S2

S4

C

FE

Page 21: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

21 21

Scan-Line & dynamische Ordnung

A

BF

C

D

ES1

S3

S2

S4

C

Page 22: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

22 22

Scan-Line & dynamische Ordnung

A

BF

C

D

ES1

S3

S2

S4

Page 23: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

23 23

Zusatzfrage: Wann wird der Schnittpunkt S1 erkannt?

A

S1

Übung: Wird ein Schnittpunkt ggf. mehr als einmal erkannt?

C

D

E

B

Page 24: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

24 24

Vereinfachende Annahmen

Annahme• 2 Segmente schneiden sich

höchstens in einem Punkt

• in keinem Punkt schneiden sich mehr als 2 Segmente

• die x-Koordinaten aller Segmente sind paarweise verschieden

• kein Segment ist vertikal

Gegenbeispiele

Page 25: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

25 25

Algorithmus Scan-Line

Input:

S: eine Menge von Segmenten

Output:

die Schnittpunkte der Elemente von S

Sei

T = Endpunkte der Segmente von S nach x-Koordinaten sortiert (Haltepunkte)

L = // aktive Segmente von S

while T do

bestimme und entferne den nächsten Punkt pT

x ist x-Koordinate von p

case: p ist linker Endpunkt von sfuege_ein(s,x,L)sl = vorgaenger(s,x,L)sr = nachfolger(s,x,L)schnitt(sl,s,T);schnitt(s,sr,T);

p ist rechter Endpunkt von ssl = vorgaenger(s,x,L)sr = nachfolger(s,x,L)entferne(s,x,L)schnitt(sl,sr,T)p ist Schnittpunkt von s und tvertausche(s,t,L,x) // t < ssl = vorgaenger(t,x,L)sr = nachfolger(s,x,L)schnitt(sl,t,T)schnitt(s,sr,T)

Page 26: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

26 26

Algorithmus (II)

fuege_ein(s,x,L): fügt das Segment s in die Menge L ein entsprechend der Ordnung an der Stelle x

entferne(s,x,L): entfernt das Segment s aus L an der Stelle x

nachfolger(s,x,L): liefert den Nachfolger von s in L an der Stelle x, falls vorhanden

vorgaenger(s,x,L): liefert den Vorgänger von s in L an der Stelle x, falls vorhanden

schnitt(s,t,T): prüft s und t auf Schnitt. Berechnet ggf. den Schnitt-punkt p und fügt ihn als neuen Haltepunkt in T ein.

offene Probleme: eine geeignete Datenstruktur für Teine geeignete Datenstruktur für LPrüfung auf Schnitt, Berechnung des Schnittpunkts

Page 27: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

27 27

Datenstrukturen für T und S

• Datenstrukur für T– AVL-Baum

– letztes Semester

• was ist ein AVL-Baum– erstens ein Suchbaum

– zweitens ausgeglichen

• Datenstruktur für L– AVL-Baum?

– Problem: „Vorgänger“ und „Nachfolger“ findendas wird vom AVL-Baum nicht unterstützt

– also: Variante des AVL-Baums

• alle Informationen sind in Blättern (nicht in inneren Knoten)

• die Blätter bilden eine doppelt verkettete Liste

Page 28: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

28 28

Eine Variante des AVL-Baums

• mit einer doppelt verketteten Liste der Blätter

für die Menge der aktiven Elemente

Page 29: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 6 SS 2001 Segmentschnitt III.

Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6 Lutz Plümer - Diskrete Mathematik - 2. Semester - SS 2001 - Vorlesung 6

29 29

für die Haltepunkte ...

• ...mit den Operationen– Einfügen eines gefundenen Schnittpunktes– Finden und Entfernen des nächsten (also minimalen)

Elements ...

• ... genügt ein „normaler“ AVL-Baum• obwohl man mit Kanonen auf Spatzen schießt• besser: ein Heap (wie bei Dijkstra)