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

35
Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische Algorithmen, Segmentschnitt

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 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

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

Diskrete Mathematik IIVorlesung 4

04.05.00

• Tiefen- und Breitendurchlauf• geometrische Algorithmen, Segmentschnitt

Page 2: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

22

Übersicht

• Abschluss Graph-Algorithmen– Tiefendurchlauf

• Beispiel• rekursiver Algorithmus

– Breitendurchlauf

• Beginn Geo-Algorithmen– Prüfung auf Schnittfreiheit– Heute: Schnitt zweier Segmente– Nächste Woche: Schnitt von n Segmenten

Page 3: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

33

Was ist neu

• In einem binären Baum hat jeder Knoten höchstens zwei Nachfolger, in einem Graphen beliebig viele

• Ein Baum ist immer zyklenfrei, ein Graph kann Zyklen enthalten (z.B. Do – Du – D – W im Beispiel)

• In einem Zyklus kann man unendlich viel Zeit verbringen

• Lösung: Faden der Ariadne (Quelle: Sagen des klassischen Altertums)

• Moderne Version: ein Boolescher Array „besucht“

Page 4: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

44

Tiefendurchlauf

Do

Ha

W

Du

K

D

Page 5: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

55

Tiefendurchlauf

aktuell

Do

Ha

W

Du

K

D

Page 6: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

66

Tiefendurchlauf

Do

Ha

W

Du

K

D

besucht

Page 7: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

77

Do

Ha

W

Du

K

D

Tiefendurchlauf

Page 8: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

88

Tiefendurchlauf

kein Nachfolger -backtracking

Do

Ha

W

Du

K

D

Page 9: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

99

Tiefendurchlauf

Do

Ha

W

Du

K

D

Page 10: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

1010

Do

Ha

W

Du

K

D

Tiefendurchlauf

Alle Nachfolgersind bereits

besucht

Page 11: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

1111

Tiefendurchlauf

Do

Ha

W

Du

K

D

Page 12: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

1212

Tiefendurchlauf

Do

Ha

W

Du

K

D

Page 13: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

1313

Tiefendurchlauf

Do

Ha

W

Du

K

D

Page 14: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

1414

Tiefendurchlauf

Do

Ha

W

Du

K

D

Page 15: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

1515

Tiefendurchlauf

Do

Ha

W

Du

K

D

Page 16: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

1616

Tiefendurchlauf

Do

Ha

W

Du

K

D

Page 17: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

1717

Tiefendurchlauf als rekursiver Algorithmus

tiefensuche(k) //Tíefendurchlauf vom Knoten k aus{

if(besucht[k] == false){

drucke k;besucht[k] = true;

for(jeder Nachfolger ki von k){

tiefensuche(ki);}

}}

Page 18: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

1818

class BST { ... void Breitendurchlauf() {

SohnListe ws = new SohnListe(); Knoten aktuell;ws.FügeAn(wurzel); while ((aktuell = ws.Entferne()) != null) { System.out.println(aktuell.GibWert()); ws.FügeAn(aktuell.GibLinks()); ws.FügeAn(aktuell.GibRechts()); }

} ...}

entf

ern

e

Tes

t au

f E

nd

e

Breitendurchlauf (binärer Suchbaum)

Page 19: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

1919

class BST { ... void Breitendurchlauf(k) {

SohnListe ws = new SohnListe(); Knoten aktuell;ws.FügeAn(k); while ((aktuell = ws.Entferne()) != null) { System.out.println(aktuell.GibWert()); ws.FügeAn(aktuell.GibLinks()); ws.FügeAn(aktuell.GibRechts()); }

} ...}

Breitendurchlauf

besucht[k] = true;

Page 20: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

2020

class BST { ... void Breitendurchlauf(k) {

SohnListe ws = new SohnListe(); Knoten aktuell;ws.FügeAn(k);besucht[k] = true; while ((aktuell = ws.Entferne()) != null) { System.out.println(aktuell.GibWert()); ws.FügeAn(aktuell.GibLinks()); ws.FügeAn(aktuell.GibRechts()); }

} ...}

Breitendurchlauf

Verarbeiteneines Knotens

Page 21: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

2121

class BST { ... void Breitendurchlauf(k) {

SohnListe ws = new SohnListe(); Knoten aktuell;ws.FügeAn(k);besucht[k] = true; while ((aktuell = ws.Entferne()) != null) { System.out.println(aktuell.GibWert()); for(jeder Nachfolger ki von aktuell) {

if(besucht[ki] == false){ ws.FügeAn(ki); besucht[ki] = true; }

} } } ... }

Breitendurchlauf

Page 22: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

2222

Prüfung auf Schnittfreiheit

• 1. Idee– Berechnung der Geradengleichungen g und g‘ der

Segmente s und s‘– Schnittpunkt p von g und g‘– prüfe ob p in s und s‘

Page 23: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

2323

Schnittpunktberechnung

Gegeben: Endpunkte der Segmente

Geradengleichung für zwei Punkte:

)( 112

121 xx

xx

yyyy

bxay :g '' bxay :g'

Page 24: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

2424

Prüfung auf Schnittfreiheit

• 1. Idee– Berechnung der Geradengleichungen g und g‘ der

Segmente s und s‘– Schnittpunkt p von g und g‘– prüfe ob p in s und s‘

• Problem– vertikale Segmente– Vermeidung unangenehmer Sonderfälle

Page 25: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

2525

Segmentschnitt I

g1

g2

c)

g2g1

b)

g1

g2

a)

Page 26: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

2626

Segmentschnitt II

• Reduktion auf das Problem:

P1, P2 liegen auf der gleichen / verschiedenen Seiten der durch g induzierten Geraden

• Homogene Koordinaten:P1 = (x1,y1,w1)P2 = (x2,y2,w2)P = (x,y,w)

• w = w1 = w2 = 1

g auf P liegt ist, 0D wenn

g von rechts P liegt ist, 0D wenn

g von links P liegt ist, 0D wenn

21

21

21

21

www

yyy

xxx

DPPPD ),,(

x

y

P1

P2

P

s

D > 0

D < 0

D = 0

Page 27: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

2727

X

Y

Z

Was wird durch die Determinante berechnet?

x

y

P2

P1

P

Vektoren spannenParallelepiped auf

1p

2p

p

1

Page 28: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

2828

Spatprodukt

Das Spatprodukt ergibt einen Skalar, der zahlenmäßig gleich dem Volumen des von den drei Vektoren gebildeten Parallelepipeds ist; das Ergebnis ist positiv, falls , und ein Rechtssystem, negativ, falls sie ein Linkssystem bilden.

c) b a(

a

b

c

zzz

yyy

xxx

cba

cba

cba

a b c - c a b - b c a-

b a c a c b c b a c) b a(

Page 29: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

2929

X

Y

Z

1

Rechts- oder Linkssystem?

21 pp

P2

1p

2p

P1

P

p

Bilden einRechtssystem

x

y

Page 30: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

3030

X

Y

Z

1

Rechts- oder Linkssystem?

P2

1p

2p

P1

P

p

x

y

bilden ein Rechtssystem21 p und p ,p

D > 0

Page 31: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

3131

X

Y

Z

1

Rechts- oder Linkssystem?

21 pp

P1

2p

1p

P2

P

p

x

y

Page 32: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

3232

X

Y

Z

1

Rechts- oder Linkssystem?

P1

P2

P

p

2p

1p

x

y

bilden ein Linkssystem21 p und p ,p

D < 0

Page 33: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

3333

X

Y

Z

1

Rechts- oder Linkssystem?

D = 0Es wird kein

Parallelepipedaufgespannt

P1

1p

2p

P2

P

p

x

y

Page 34: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

3434

Einfacher Segmentschnitt I

S1 = det ( P1,P3,P4) Def.: Vor.: Alle Determinanten sind 0:S2 = det ( P2,P3,P4) g und g` schneiden sich genau dann, wenn S1, S2

S3 = det ( P3,P1,P2) sowie S3, S4 jeweils verschiedene Vorzeichen S4 = det ( P4,P1,P2) haben.

P2

P1

P3 P4

P2

P3

P4

P1g

g`

P2

P1

P3

P4

Page 35: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung 4 04.05.00 Tiefen- und Breitendurchlauf geometrische.

Einfacher Segmentschnitt II

Wenn alle Determinanten gleich Null sind, dann folgt daraus, daß alle vier Punkte kollinear sind.

- eine Determinante ist Null:

=> Algorithmus: Einsparen von Multiplikationen

Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00Lutz Plümer - Diskrete Mathematik II - SS 2000 - Vorlesung 4 - 04.05.00

3535