1.2 KiB
1.2 KiB
Um den Abstand eines Punktes P von einer Strecke \overline{AB} im zweidimensionalen Raum zu berechnen, gehst du wie folgt vor:
Gegeben:
- Punkt
P = (x_0, y_0) - Strecke mit den Endpunkten
A = (x_1, y_1),B = (x_2, y_2)
Schritt-für-Schritt-Lösung:
-
Vektorbildung:
\vec{AP} = (x_0 - x_1, y_0 - y_1)\vec{AB} = (x_2 - x_1, y_2 - y_1)
-
Skalare Projektion von
\vec{AP}auf $\vec{AB}$:t = \frac{\vec{AP} \cdot \vec{AB}}{|\vec{AB}|^2} -
Fallunterscheidung:
- Wenn
t < 0: nächstgelegener Punkt istA - Wenn
t > 1: nächstgelegener Punkt istB - Wenn
0 \leq t \leq 1: Projektion fällt auf die Strecke, d.h. PunktQ = A + t \cdot \vec{AB}
- Wenn
-
Abstandsberechnung:
- Falls
t < 0odert > 1: Abstand =|P - A|bzw.|P - B| - Sonst: Abstand =
|P - Q|
- Falls
Beispiel in Formel:
\text{Abstand} =
\begin{cases}
\sqrt{(x_0 - x_1)^2 + (y_0 - y_1)^2}, & \text{wenn } t < 0 \\
\sqrt{(x_0 - x_2)^2 + (y_0 - y_2)^2}, & \text{wenn } t > 1 \\
\sqrt{(x_0 - x_q)^2 + (y_0 - y_q)^2}, & \text{sonst}
\end{cases}
wobei:
x_q = x_1 + t \cdot (x_2 - x_1), \quad y_q = y_1 + t \cdot (y_2 - y_1)