3.3. 点到线性对象的距离

3.3. 点到线性对象的距离

3.3.1. 点到直线的距离

$\vec d \cdot (Y – L(\hat t)) = \vec d \cdot (Y – P – \hat t\vec d) = \vec d \cdot (Y – P) – \hat t{\left\| {\vec d} \right\|^2} = 0 \tag{3.15}$

解得$$\hat t = \vec d \cdot (Y – P)/{\left\| {\vec d} \right\|^2}$$，把$$\hat t$$值代入直线方程，得到点$$L(\hat t)$$，点$$Y$$与点$$L(\hat t)$$距离的平方是，$${\left\| {Y – L(\hat t)} \right\|^2}$$，可得：

${{\mathop{\rm dist}\nolimits} ^2}(L,Y) = {\left\| {Y – L(\hat t)} \right\|^2} = {\left\| {Y – P – \hat t\vec d} \right\|^2} = {\left\| {Y – P} \right\|^2} – \frac{{{{\left( {\vec d \cdot (Y – P)} \right)}^2}}}{{{{\left\| {\vec d} \right\|}^2}}} \tag{3.16}$

3.3.2. 点到射线的距离

${{\mathop{\rm dist}\nolimits} ^2}(L,Y) = \left\{ {\begin{array}{*{20}{l}}{{{\left\| {Y – P} \right\|}^2} – \frac{{{{\left( {\vec d \cdot (Y – P)} \right)}^2}}}{{{{\left\| {\vec d} \right\|}^2}}},}&{\vec d \cdot (Y – P) > 0}\\{{{\left\| {Y – P} \right\|}^2},}&{\vec d \cdot (Y – P) \le 0}\end{array}} \right. \tag{3.17}$

3.3.3. 点到线段的距离

${{\mathop{\rm dist}\nolimits} ^2}(S,Y) = \left\{ {\begin{array}{*{20}{l}}{{{\left\| {Y – {P_0}} \right\|}^2},}&{\hat t \le 0}\\{{{\left\| {Y – {P_0}} \right\|}^2} – \frac{{{{\left( {\vec d \cdot (Y – {P_0})} \right)}^2}}}{{{{\left\| {\vec d} \right\|}^2}}},}&{\hat t \in (0,1)}\\{{{\left\| {Y – {P_1}} \right\|}^2},}&{\hat t \ge 0}\end{array}} \right. \tag{3.18}$