In the space, two straight lines can coincide, can be parallels, secants or intersect. The angles that they form are defined in a different way in every case. We will say:

- If two straight lines coincide or are parallel they form an angle of $$0^\circ$$.
- If two straight lines are secant, they determine four angles that are equal in pairs. The smallest angle will be said to be the angle between the lines.
- If two straight lines cross, the angle between them is the smallest of the angles that is formed by the parallel to one of the lines that intersects the other one.

Therefore, as on the plane, the cosine of the angle $$\alpha$$ will coincide (except maybe the sign) with the angle formed by the governing vectors of the straight line. Therefore,

$$$\cos(\widehat{r\ s})=\cos\alpha=|\cos(\widehat{\vec{u}\ \vec{v}})|= \Big|\dfrac{\vec{u}\cdot\vec{v}}{|\vec{u}||\vec{v}|}\Big|= \dfrac{|\vec{u}\cdot\vec{v}|}{|\vec{u}||\vec{v}|}$$$

where $$\vec{u}$$ and $$\vec{v}$$ governing vectors of the straight lines $$r$$ and $$s$$.

Therefore,

$$$ \alpha=\arccos\Big(\dfrac{|\vec{u}\cdot\vec{v}|}{|\vec{u}||\vec{v}|} \Big) \qquad \alpha \in [0,\dfrac{\pi}{2}]$$$

Finally, if $$\vec{u}=(u_1,u_2,u_3)$$ and $$\vec{v}=(v_1,v_2,v_3)$$, the expression - given in components - of the previous formula is:

$$$ \cos(\alpha)=\dfrac{|u_1 v_1+u_2 v_2+u_3 v_3|} {\sqrt{u_1^2+u_2^2+u_3^2}\sqrt{v_1^2+v_2^2+v_3^2}}$$$

Compute the angle between the following lines: $$$ r:\dfrac{x+2}{5}=\dfrac{y-1}{2}=z \quad \text{ and } \quad s:\left\{ \begin{array}{l} x+y+2z=3 \\ x-y-z=1 \end{array} \right. $$$

First of all we must look for the governing vector of $$r$$ and $$s$$:

- A governing vector of $$r$$ is $$\vec{u}=(5,2,1)$$.
- To find a governing vector of $$s$$, we choose $$z$$ as a parameter and solve the equations system using Cramer, obtaining:

$$$ s: \left\{ \begin{array}{l} x=2-\dfrac{1}{2}k \\ y=1-\dfrac{3}{2}k \\ z=k \end{array} \right. $$$

and therefore a governing vector of $$s$$ is $$\vec{u}=(-1,-3,2)$$.

Now we can already apply the formula previously described:

$$$ \begin{array}{rl} \cos(\alpha)=&\dfrac{|u_1 v_1+u_2 v_2+u_3 v_3|} {\sqrt{u_1^2+u_2^2+u_3^2}\sqrt{v_1^2+v_2^2+v_3^2}}= \dfrac{|5\cdot1+2\cdot3+1\cdot(-2)|} {\sqrt{5^2+2^2+1^2}\sqrt{1^2+3^2+(-2)^2}} \\ =& \dfrac{9}{\sqrt{30}\sqrt{14}}=0.439 \end{array}$$$

Therefore,

$$$\alpha=\arccos(0.439)=63,95^\circ$$$