distance between lines in the space (with calculus) If I have two lines $$
\eqalign{
  & L_1 \left( t \right):p_1  + td_1   \cr 
  & L_2 \left( q \right):p_2  + qd_2  \cr} 
$$
living in $\mathbb{R}^n$, there exists a classical formula to find the distance between them involving dot and cross products.  The question is: 
can I deduce that formula only using calculus? (In this case, 2 variables)
i.e., find the values such that the function
$$
f\left( {t,q} \right) = \left \| L_1 (t) - L_2(t) \right \| = \left \| p_1  + td_1  - p_2  - qd_2   \right\|
$$
reaches its minimum value.
Oh sorry; for simplicity, to have the natural cross product, just take $\mathbb{R}^3$.
 A: Consider the distance squared between two points on these lines are $d_2(t_1, t_2) = \vert\vert p_1 - p_2 + t_1 q_1 - t_2 q_2 \vert\vert^2$. 
Simple algebra shows, here $(u,v)$ denotes dot product of two vectors:
$$
  d_2(t_1,t_2) = \vert p_{12} \vert^2 + 2 t_1 (p_{12}, q_1)- 2 t_2 (p_{12},q_2) + t_1^2 \vert q_1 \vert^2 + t_2^2 \vert q_2 \vert^2 - 2 t_1 t_2 (q_1,q_2) 
$$
You now minimize it by requiring derivatives with respect to $t_1$ and $t_2$ to vanish.  This yields
$$
 t_1 = \frac{ (p_{12},q_1) \vert q_2\vert^2 - (p_{12},q_2) (q_1, q_2) }{(q_1, q_2)^2 - \vert q_1 \vert^2 \vert q_2 \vert^2} \; \;\; \text{and} \;\;\;

 t_2 = - \frac{ (p_{12},q_2) \vert q_1\vert^2 - (p_{12},q_1) (q_1, q_2) }{(q_1, q_2)^2 - \vert q_1 \vert^2 \vert q_2 \vert^2} 
$$
Upon substitution I obtain the minimal distance squared is 
$$
\vert p_{12} \vert^2 + \frac{ \vert q_1\vert^2 (p_{12},q_2)^2 + \vert q_2\vert^2 (p_{12},q_1)^2 - 2 (q_1,q_2)(p_{12},q_1)(p_{12},q_2) }{ (q_1, q_2)^2 - \vert q_1 \vert^2 \vert q_2 \vert^2}
$$
where $p_{12}=p_1-p_2$.
A: In the past, I have solved these types of problems without calculus just by requiring the minimizing line to be orthogonal to whatever it was supposed to minimize the distance between. 
Since I am lazy, I will rewrite the equations as 
$ L_1 ( p):a  + p b $ 
and
  $ L_2 ( q):c  + q d $.
We want to find values of $p$ and $q$ such that, 
if $P = L_1(p)$ and $Q = L_2(q)$, then
$P-Q$ is orthogonal to both  $b$ and $d$.
Using "$.$" for dot product (I don't see where cross product is needed),
this becomes
$$0 = ( a  + p b - c  - q d).b = ( a  + p b - c  - q d).d$$
or, letting $g = c-a$,
$$\eqalign{p |b|^2 - q(d.b) = g.b \cr
p(b.d)-q |d|^2 = g.d\cr}$$
Solving these for $p$ and $q$ and substituting back in $P$ and $Q$ should give the points (modulo and errors on my part). Note that, if $b$ and $d$ are not proportional, Cauchy-Schwarz shows this equation has a unique solution.
