Gerade 1:
=> v1 = p1 + t1 * (p2 - p1)
=> v1_x = v1_p1_x + t1 * (v1_p2_x - v1_p1_x)
v1_y = v1_p1_y + t1 * (v1_p2_y - v1_p1_y)
Ermittle den Ortsvektor für die Gerade v1
==> v1_dv_x = (v1_p2_x - v1_p1_x)
v1_dv_y = (v1_p2_y - v1_p1_y)
=> v1_x = v1_p1_x + t1 * v1_dv_x
v1_y = v1_p1_y + t1 * v1_dv_y
Gerade 2:
=> v2 = p1 + t2 * (p2 - p1)
=> v2_x = v2_p1_x + t2 * (v2_p2_x - v2_p1_x)
v2_y = v2_p1_y + t2 * (v2_p2_y - v2_p1_y)
Ermittle den Ortsvektor für die Gerade v2
==> v2_dv_x = (v2_p2_x - v2_p1_x)
v2_dv_y = (v2_p2_y - v2_p1_y)
=> v2_x = v2_p1_x + t2 * v2_dv_x
v2_y = v2_p1_y + t2 * v2_dv_y
Gleichsetzen der beiden Geraden
=> v1 = v2
=> v1_p1_x + t1 * v1_dv_x = v2_p1_x + t2 * v2_dv_x | - v1_p1_x
v1_p1_y + t1 * v1_dv_y = v2_p1_y + t2 * v2_dv_y | - v1_p1_y
=> t1 * v1_dv_x = v2_p1_x + t2 * v2_dv_x - v1_p1_x | - t2 * v2_dv_x
t1 * v1_dv_y = v2_p1_y + t2 * v2_dv_y - v1_p1_y | - t2 * v2_dv_y
=> t1 * v1_dv_x - t2 * v2_dv_x = v2_p1_x - v1_p1_x
t1 * v1_dv_y - t2 * v2_dv_y = v2_p1_y - v1_p1_y
=> [B]I.[/B] (v1_dv_x * t1) - (v2_dv_x * t2) = v2_p1_x - v1_p1_x
[B]II.[/B] (v1_dv_y * t1) - (v2_dv_y * t2) = v2_p1_y - v1_p1_y
Da wir den Wert für t1 oder t2 benötigen gibt es jetzt einige verschiedene Möglichkeiten, t1 zu ermitteln:
1. Wenn v2_dv_x null ist, so gilt: [B]t1 = (v2_p1_x - v1_p1_x) / v1_dv_x[/B]
2. Wenn v2_dv_y null ist, so gilt: [B]t1 = (v2_p1_y - v1_p1_y) / v1_dv_y[/B]
3. Wenn v2_dv_x ungleich v2_dv_y ist, so muss v2_dv_x gleich v2_dv_y oder v2_dv_y gleich v2_dv_x sein, damit die Schritte 4. oder 5. zur ermittlung von t1 durchgeführt werden können. Dazu kann man ermitteln ob v2_dv_x > v2_dv_y ist, wenn dies der Fall ist, so gilt: I. / (v2_dv_x / v2_dv_y), ansonsten gilt: II. / (v2_dv_y / v2_dv_x). Wenn dies getan wurde, so muss entweder der Punkt 4, oder der Punkt 5 durchgeführt werden um t1 zu erhalten.
4. Wenn v2_dv_x gleich v2_dv_y ist, und v2_dv_x - v2_dv_y null ergibt, so kann durch I. - II. t1 ermittelt werden:
=> [B]I.[/B] (v1_dv_x * t1) - (v2_dv_x * t2) = v2_p1_x - v1_p1_x
[B]II.[/B] (v1_dv_y * t1) - (v2_dv_y * t2) = v2_p1_y - v1_p1_y
=> I. - II.
=> (v1_dv_x * t1) - (v1_dv_y * t1) = (v2_p1_x - v1_p1_x) - (v2_p1_y - v1_p1_y)
=> (v1_dv_x - v1_dv_y) * t1 = (v2_p1_x - v1_p1_x) - (v2_p1_y - v1_p1_y)
=> t1 = ((v2_p1_x - v1_p1_x) - (v2_p1_y - v1_p1_y)) / (v1_dv_x - v1_dv_y)
5. Wenn v2_dv_x gleich v2_dv_y ist, und v2_dv_x + v2_dv_y null ergibt, so kann durch I. + II. t2 ermittelt ähnlich wie oben ermittelt werden.
Da wir jetzt den Wert für t1 haben, können wir Ihn einfach einsetzen, um t2 zu erhalten.
Wenn wir dann t2 haben setzen wir dies in v1 oder v2 ein und erhalten so die Schnittpunkte, etwa so:
=> [B]I.[/B] (v1_dv_x * t1) - (v2_dv_x * t2) = v2_p1_x - v1_p1_x
[B]II.[/B] (v1_dv_y * t1) - (v2_dv_y * t2) = v2_p1_y - v1_p1_y
=> Einsetzen von t1 in I.
=> -(v2_dv_x * t2) = v2_p1_x - v1_p1_x - (v1_dv_x * t1)
=> -(v2_dv_x * t2) = v2_p1_x - v1_p1_x - (v1_dv_x * t1)
=> t2 = (v2_p1_x - v1_p1_x - (v1_dv_x * t1)) / - v2_dv_x
=> Einsetzen von t1 in v1 und t2 in v2
=> Vergleichen von v1 und v2, wenn die beiden Gleich sind, so haben die beiden Geraden einen gemeinsamen Schnittpunkt, wenn nicht, so schneiden sich die beiden Geraden nicht.
=> Prüfen ob t1 oder t2 größer als 1 oder kleiner als 0 sind, ist dies der Fall, so liegt der Schnittpunkt nicht auf dem Bereich der definierten Geraden, sondern auserhalb und es gibt auch keinen Schnittpunkt.
=> Fertig :)