Given two lines:

$$r_1(t) = (a_1, b_1, c_1) + t(p_1, q_1, r_1)$$

$$r_2(s) = (a_2, b_2, c_2) + s(p_2, q_2, r_2)$$

I have calculated the cross product of the direction vectors to get the vector perpendicular to both lines:

$$\vec n = (p_1, q_1, r_1) \times (p_2, q_2, r_2)$$

Which gives the vector $\vec n$.

I then got a vector $\vec V$ between a point on each line, and calculated the minimum distance $d$ between both lines by finding the scalar projection of $\vec V$ onto $\vec n$.

$$d = \frac{|\vec V \cdot \vec n|}{|\vec n|}$$

I now need the points on both lines where this minimum distance is achieved, how would I go about doing that?

Thanks for any help.


2 Answers 2


$L_1(t) = (a_1, b_1, c_1) + t(p_1, q_1, r_1)$

$L_2(s) = (a_2, b_2, c_2) + s(p_2, q_2, r_2)$

If two points on lines $L_1$ and $L_2$ are $A$ and $B$ resp.,

$\vec {AB} = (a_1-a_2+tp_1-sp_2, \, b_1-b_2+tq_1-sq_2, \, c_1-c_2+tr_1-sr_2)$

to find two points on lines with minimal distance, the vector $\vec {AB}$ should be perpendicular to both lines. So the dot product of $\vec {AB}$ to the directional vectors of both lines be zero.

$\vec {AB}\cdot(p_1,q_1,r_1) = 0$

$\vec {AB}\cdot(p_2,q_2,r_r) = 0$

Solve for $s$ and $t$ and that should give you two points. You can also find the minimum distance from there.




$$ \cases{ r_1 = r_{01}+t\vec v_1\\ r_2 = r_{02}+s\vec v_2} $$

we have

$$ d^2(t,s)=|| r_1-r_2||^2 = t^2||\vec v_1||^2+s^2||\vec v_2||^2+2(r_{01}-r_{02})\cdot \vec v_1 t-2(r_{01}-r_{02})\cdot \vec v_2 s-2 s t\vec v_1\cdot\vec v_2 $$

now the minimum to this quadratic form is attained at the stationary point given by the solution to

$$ \nabla d^2(t,s) = 0 $$


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .