:PROPERTIES:
:ID: 2c9478e0-4c97-45d0-b4e6-9003425e2c3c
:mtime: 20231017010409 20231014011418
:ctime: 20231014011329
:END:
#+title: shortest distance between 2 lines
#+filetags: :public:project:
* Definition
Given 2 lines, return the shortest distance between them
* Vector Method
Let
$\vec{r} = \vec{a} + \lambda \vec{t}$ and let
$\vec{s} = \vec{b} + \mu \vec{u}$.
The line joining them will be parallel to
$\vec{t} \times \vec{u}$.
Using [[id:856a2afe-f299-4eb8-b0ef-018aa5256d8c][shortest distance from line to a point]], we get
the distance as
\[d = \frac{|(\vec{b} - \vec{a}) \cdot (\vec{t} \times \vec{u})|}{|\vec{t} \times \vec{u}|} \]
Note that the pattern of $\cdot$ followed by $\times$ is called
[[id:e72ab120-e332-4c9d-bf88-ea02dcd4eb99][scalar triple product.]]
** When do 2 lines intersect?
2 lines interesect iff $d = 0$, wich means they intersect iff
\[(\vec{b} - \vec{a}) \cdot (\vec{t} \times \vec{u}) = 0\]
** Shortest distance between 2 parallel lines
if 2 lines are parallel, the above method results in dividing by 0, so
\[d = \frac{|(\vec{b} - \vec{a}) \times \vec{t}|}{|\vec{t}|}\]