TITLE: Find intersection of two 3D lines
QUESTION [20 upvotes]: I have two lines $(5,5,4) (10,10,6)$ and $(5,5,5) (10,10,3)$ with same $x$, $y$ and difference in $z$ values.
Please some body tell me how can I find the intersection of these lines.
EDIT: By using the answer given by coffemath I would able to find the intersection point for the above given points. But I'm getting a problem for $(6,8,4) (12,15,4)$ and $(6,8,2) (12,15,6)$. I'm unable to calculate the common point for these points as it is resulting in Zero.
Any ideas to resolve this?
Thanks, 
Kumar.

REPLY [19 votes]: There are at least two ways to approach such problems, through vectors as such and through coordinates.  Some problems are easier one way, and this one is definitely easier via coordinates.  Several such solutions have been given.  But the more ways you can solve a problem, the better you probably understand the underlying mathematics.  So I'll share a vector method.
We can arrive at the solution without the use of coordinates, except as a matter of calculation of the final answer.  We also assume that a line is given by a point and a (nonzero) direction vector (in either direction).  In the examples given, the lines are defined by two points, but a direction vector may be obtained by taking the difference in the coordinates of the two given points.
Here is the construction.  We leave the proof as an exercise, so that the interested reader may benefit by working it out (hint: the Law of Sines is helpful).
Let $\alpha$, $\beta$ be the given lines.
Let $C$, $D$ be points on $\alpha$, $\beta$, resp.  If $C$ is on $\beta$ or $D$ is on $\alpha$, we have found the point of intersection.  So let us assume they are not.
Let ${\bf e}$ and ${\bf f}$ be direction vectors of $\alpha$, $\beta$, resp.
Let ${\bf g} = \vec{CD}$.
Let $h = ||{\bf f} \times {\bf g}||$, $k=||{\bf f} \times {\bf e}||$.
If either is $0$, then there is no intersection; otherwise, they are nonzero and proceed.
Let ${\bf l} = {h \over k} {\bf e}$.
Then one of $M = C \pm {\bf l}$ is the point of intersection
(or depending on the notation you prefer, $\vec{OM} = \vec{OC} \pm {\bf m}$),
where the sign may be determined as follows:
If ${\bf f} \times {\bf g}$ and ${\bf f} \times {\bf e}$ point in the same direction, then the sign is $+$;
otherwise, the sign is $-$.

One can compose all the steps to get a formula:
$$M = C \pm {||{\bf f} \times {\vec{CD}}|| \over ||{\bf f} \times {\bf e}||}\,{\bf e}\,.$$
If you want to check, we can, in the second example, take $C = (6,8,4)$, $D = (6,8,2)$
and ${\bf e} = (6,7,0)$ and ${\bf f} = (6,7,4)$.  Therefore ${\bf g} = \vec{CD} = (0,0,-2)$.
So ${\bf f} \times {\bf g} = (-14, 12,0)$ and ${\bf f} \times {\bf e} = (-28, 24, 0)$,
which point in the same direction; so we take the $+$ sign.
Therefore the point of intersection is $C + {1\over2}{\bf e} = (9,{23\over2},4)$.