0

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.

  • 1
    What information do you have about your two lines? – kandb Jan 24 '23 at 14:40
  • Thank you for your reply! I have the start and end coordinates for each line. At the moment I am trying to create a vector equation for each line – ricehound Jan 24 '23 at 14:45
  • You write “I have the start and end coordinates for each line.” Are you dealing with lines, or rather with segments (lines don't have such things as “start" or “end”, but segments do; rather call them extremities)? – jp boucheron Jan 24 '23 at 15:15

1 Answers1

1

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*}

kandb
  • 1,349
  • Thank you very much! I would just like to ask, what are i, j and k? Also, having solved your equations, would I then plug those values into the equation in my question? I apologise for my ignorance – ricehound Jan 24 '23 at 15:03
  • Check out the edit I just made--hopefully that clarifies some things! Once you have found $\mathbf{X}{1}$, $\mathbf{X}{2}$, $\mathbf{D}{1}$, and $\mathbf{D}{2}$, then yes, you only need to plug those into the equation. Keep in mind, though, that for vectors $\mathbf{a}$ and $\mathbf{b}$, the product $\mathbf{a}\times\mathbf{b}$ is the cross product and $\mathbf{a}\cdot\mathbf{b}$ is the scalar product (or dot product). – kandb Jan 24 '23 at 15:10
  • Thank you very much! You are amazing – ricehound Jan 24 '23 at 15:13