






















本文记录判断线段是否相交的方法。

判断 AB 和 CD 向量叉乘是否为 0, 如果为 0 则平行,如果 AB 和 AC、 AD 叉乘也为 0 则共线。
随后查看线段是否重叠,分别查看 x, y 是否重叠即可判断。
此种情况下线段相交有两种情况

$$ \begin{array}{c} (\vec{AC}\times\vec{AB})\cdot(\vec{AD}\times\vec{AB})<0 \\ (\vec{CA}\times\vec{CD})\cdot(\vec{CB}\times\vec{CD})<0 \end{array} $$
$$ \begin{array}{c} (\overrightarrow{AC}\times\overrightarrow{AB})\cdot(\overrightarrow{AD}\times\overrightarrow{AB})=0 \\(\overrightarrow{CA}\times\overrightarrow{CD})\cdot(\overrightarrow{CB}\times\overrightarrow{CD})=0 \end{array} $$
假设交点为$P$,则有$P= A+ \overrightarrow {AB}* t$, $t\in [ 0, 1]$且$P= C+ \overrightarrow {CD}* u$, $u\in [ 0, 1]$ 即 $$ \begin{array}{c} A+ \overrightarrow {AB}* t= C+ \overrightarrow {CD}* u \\ \overrightarrow {AB}* t= \overrightarrow {AC}+ \overrightarrow {CD}* u \end{array} $$ 由于向量自身的叉乘为0,所以上式两边同时叉乘 $\overrightarrow {CD}$ 可得: $$ \vec{CD}\times\vec{AB}*t=\vec{CD}\times\vec{AC} $$ 变形可得: $$ t=\frac{\overrightarrow{CD}\times\overrightarrow{AC}}{\overrightarrow{CD}\times\overrightarrow{AB}},\:t\in[0,1] $$ 同理,两边同时叉乘$\overrightarrow{AB}$可得:$-\overrightarrow{AB}\times\overrightarrow{CD}*u=\overrightarrow{AB}\times\overrightarrow{AC}$ ,所以: $$ u=\frac{\overrightarrow{AB}\times\overrightarrow{AC}}{\overrightarrow{CD}\times\overrightarrow{AB}},\:u\in[0,1] $$
文章链接:
https://www.zywvvd.com/notes/study/math/cross-segment/cross-segment/
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。