I have the straight lines:
$$d_1: \frac{x-1}2=\frac{y-3}1=\frac{z+2}1\\[4ex] d_2: \dfrac{x-1}1=\frac{y+2}{-4}=\frac{z-9}2$$
And I have to find the common perpendicular of these lines.
I have the straight lines:
$$d_1: \frac{x-1}2=\frac{y-3}1=\frac{z+2}1\\[4ex] d_2: \dfrac{x-1}1=\frac{y+2}{-4}=\frac{z-9}2$$
And I have to find the common perpendicular of these lines.
In general, let $\mathcal{H}$ be a Hilbert space over $\mathbb{K}\in\{\mathbb{R},\mathbb{C}\}$, in which $\langle\_,\_\rangle$ is the inner product where the first entry is linear over $\mathbb{K}$ and the second entry is antilinear over $\mathbb{K}$ (and $\|\_\|$ is the norm associated to this inner product). A line in $\mathcal{H}$ is a set of the form $\ell(\textbf{x},\textbf{a}):=\{\mathbf{x}t+\mathbf{a}\,|\,t\in\mathbb{K}\}$ for fixed $\mathbf{x},\mathbf{a}\in\mathcal{H}$ such that $\mathbf{x}$ is nonzero.
Suppose we have two lines $l_1:=\ell\left(\textbf{x}_1,\textbf{a}_1\right)$ and $l_2:=\ell\left(\textbf{x}_2,\textbf{a}_2\right)$ in general position (that is, $\textbf{x}_1$ and $\textbf{x}_2$ are not proportional). Without loss of generality, assume that $\left\|\textbf{x}_i\right\|=1$ for both $i=1$ and $i=2$. Hence, $\epsilon:=\left\langle \textbf{x}_1,\textbf{x}_2\right\rangle$ satisfies $|\epsilon|<1$ due to the Cauchy-Schwarz Inequality and the assumption that the lines are in general position.
We shall prove that there exist unique points $P_i\in l_i$ for $i\in\{1,2\}$ such that $\underline{P_1P_2}:=P_2-P_1$ is perpendicular to both $l_1$ and $l_2$. That is, there is a unique common perpendicular line for $l_1$ and $l_2$, provided that $l_1$ does not intersect $l_2$. (Note that this statement includes the degenerate case where $P_1=P_2$, i.e., when $l_1$ intersects $l_2$. The zero element is orthogonal to any element of $\mathcal{H}$ anyhow.)
If $P_i=\textbf{x}_it_i+\textbf{a}_i$ for some $t_i\in\mathbb{K}$, where $i\in\{1,2\}$, then the conditions $\underline{P_1P_2}\perp l_i$ for $i=1$ and for $i=2$ is equivalent to demanding that $$\left\langle \textbf{x}_1t_1+\textbf{a}_1-\textbf{x}_2t_2-\textbf{a}_2,\textbf{x}_1\right\rangle=0\text{ and }\left\langle \textbf{x}_1t_1+\textbf{a}_1-\textbf{x}_2t_2-\textbf{a}_2,\textbf{x}_2\right\rangle=0\,.$$ Therefore, $$t_1-\bar\epsilon t_2=-\left\langle \textbf{a}_1-\textbf{a}_2,\textbf{x}_1\right\rangle\text{ and }\epsilon t_1-t_2=-\left\langle\textbf{a}_1-\textbf{a}_2,\textbf{x}_2\right\rangle\,,$$ whence $$t_1=-\frac{\left\langle\textbf{a}_1-\textbf{a}_2,\textbf{x}_1-\epsilon\textbf{x}_2\right\rangle}{1-|\epsilon|^2}\text{ and }t_2=-\frac{\left\langle\textbf{a}_2-\textbf{a}_1,\textbf{x}_2-\bar{\epsilon}\textbf{x}_1\right\rangle}{1-|\epsilon|^2}\,.$$ Without the unit norm assumption, $$t_1=-\frac{ \Big\langle\textbf{a}_1-\textbf{a}_2,\left\|\textbf{x}_2\right\|^2\textbf{x}_1-\left\langle\textbf{x}_1,\textbf{x}_2\right\rangle\textbf{x}_2\Big\rangle}{\left\|\textbf{x}_1\right\|^2\left\|\textbf{x}_2\right\|^2-\big|\left\langle \textbf{x}_1,\textbf{x}_2\right\rangle\big|^2}$$ and $$t_2=-\frac{\Big\langle\textbf{a}_2-\textbf{a}_1,\left\|\textbf{x}_1\right\|^2\textbf{x}_2-\left\langle\textbf{x}_2,\textbf{x}_1\right\rangle\textbf{x}_1\Big\rangle}{\left\|\textbf{x}_2\right\|^2\left\|\textbf{x}_1\right\|^2-\big|\left\langle \textbf{x}_2,\textbf{x}_1\right\rangle\big|^2}\,.$$ Hence, $P_1$ and $P_2$ exist and are unique, as they correspond to $t_1$ and $t_2$, which have been proven to uniquely exist.
Now, for the OP's particular problem, $\mathbb{K}=\mathbb{R}$, $\mathcal{H}=\mathbb{R}^3$ with the standard inner product, $\textbf{x}_1=\frac{(2,1,1)}{\sqrt{6}}$, $\textbf{x}_2=\frac{(1,-4,2)}{\sqrt{21}}$, $\textbf{a}_1=(1,3,-2)$, and $\textbf{a}_2=(1,-2,9)$. Ergo, $\epsilon=\bar{\epsilon}=0$, which leads to $t_1=\sqrt{6}$ and $t_2=-2\sqrt{21}$. Thus, $$P_1=(2,1,1)+(1,3,-2)=(3,4,-1)$$ and $$P_2=(-2,8,-4)+(1,-2,9)=(-1,6,5)\,.$$
The classical method is as follows
First convert line equations into parametrical form
$$M_s(x=x_1+u_1s, \ \ y=y_1+v_1s, \ \ z=z_1+w_1s) \ \ \ (1)$$
and
$$N_t(x=x_2+u_2t, \ \ y=y_2+v_2t, \ \ z=z_1+w_2t) \ \ (2)$$
(you have already directing vectors $(u_1,v_1,w_1)$ and $(u_2,v_2,w_2)$.
Take arbitrary points on your lines for $(x_1,y_1,z_1)$ and $(x_2,y_2,z_2)$).
Then express that the distance, or more exactly the squared distance
$$(M_sN_t)^2=(x_2+u_2t-x_1-u_1s)^2+(y_2+v_2t-y_1-v_1s)^2+(z_1+w_2t-z_1-w_1s)^2$$
has a minimal value.
As this function of $s$ and $t$ has to be minimized, the necessary (in fact sufficient) condition is that the partial derivatives with respect to $s$ and with respect to $t$ of this expression are zero. You will obtain a linear system. Solve it, finding a certain $s_0$ and a certain $t_0$.
Now plug in (1) the value of $s=s_0$; you obtain a point $M_{s_0}$ common to the first line and thecommon perpendicular (P). The same for the second line giving a point $N_{t_0}$ belonging this time to the second line and (P). You know completely line (P) because you know two of its points. From there it is easy to find its equation.
Convert the line equations to ax + by + c format. And then take cross product of the vectors represented by (a, b, c)