institut für kartographie und geoinformation prof. dr. lutz plümer diskrete mathematik ii...
TRANSCRIPT
Institut für Kartographie und GeoinformationProf. Dr. Lutz Plümer
Diskrete Mathematik IIVorlesung 4
04.05.00
• Tiefen- und Breitendurchlauf• geometrische Algorithmen, Segmentschnitt
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
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“
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
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
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
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
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
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
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
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
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
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
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
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
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
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);}
}}
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)
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;
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
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
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‘
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'
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
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)
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
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
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(
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
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
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
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
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
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
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