I am trying to follow Isaac's answer here: How to find shortest distance between two skew lines in 3D? but I have no background in maths and can't figure out how to enter my coordinates into the equation
The equation I am trying to use is:
$$\left|\frac{\vec{D}_1\times\vec{D}_2}{|\vec{D}_1\times\vec{D}_2|}\cdot(\vec{X}_1-\vec{X}_2)\right|$$
I have implemented this in Python too:
intersect = np.linalg.norm(np.dot(np.cross(d1,d2)/np.linalg.norm(np.cross(d1,d2)), (x1-x2))
I don't know where to start, could someone go through this with me?
Thank you so much.
It is possible to write the equation of the line in vector form as
\begin{equation*} \mathbf{x}(t) = \mathbf{X} + t\mathbf{D} \end{equation*}
where $\mathbf{X}$ is the vector from the origin to a point on the line and $\mathbf{D}$ is a vector parallel to the line. So consider a line through $(x_{1},y_{1},z_{1})$ and $(x_{2},y_{2},z_{2})$. Then you could take
\begin{equation*} \mathbf{X}_{1} = x_{1}\hat{\boldsymbol{\imath}} + y_{1}\hat{\boldsymbol{\jmath}} + z_{1}\hat{\boldsymbol{k}} \end{equation*}
and
\begin{equation*} \mathbf{D}_{1} = (x_{2}-x_{1})\hat{\boldsymbol{\imath}} + (y_{2}-y_{1})\hat{\boldsymbol{\jmath}} + (z_{2}-z_{1})\hat{\boldsymbol{k}}. \end{equation*}
so the line through $(x_{1},y_{1},z_{1})$ and $(x_{2},y_{2},z_{2})$ can be represented by the equation
\begin{equation*} \mathbf{x}_{1}(t) = \mathbf{X}_{1} + t\mathbf{D}_{1}. \end{equation*}
You can do the same thing with the two points you have on the second line and write its equation as $\mathbf{x}_{2}(t) = \mathbf{X}_{2} + t\mathbf{D}_{2}$.
Edit: The vectors $\hat{\boldsymbol{\imath}}$, $\hat{\boldsymbol{\jmath}}$, and $\hat{\boldsymbol{k}}$ are the usual unit vectors in the $x$-, $y$-, and $z$-directions:
\begin{equation*} \hat{\boldsymbol{\imath}} = \left(\begin{array}{c} 1\\ 0\\ 0 \end{array}\right),\hspace{1pc} \hat{\boldsymbol{\jmath}} = \left(\begin{array}{c} 0\\ 1\\ 0 \end{array}\right),\hspace{1pc} \mbox{ and }\hspace{1pc} \hat{\boldsymbol{k}} = \left(\begin{array}{c} 0\\ 0\\ 1 \end{array}\right). \end{equation*}
So in other words,
\begin{equation*} \mathbf{X}_{1} = \left(\begin{array}{c} x_{1}\\ y_{1}\\ z_{1} \end{array}\right)\hspace{1pc} \mbox{ and }\hspace{1pc}\mathbf{D}_{1} = \left(\begin{array}{c} x_{2}-x_{1}\\ y_{2}-y_{1}\\ z_{2}-z_{1} \end{array}\right). \end{equation*}