The distance between two lines A {\displaystyle \mathbf {A} } and B {\displaystyle \mathbf {B} } , where a {\displaystyle \mathbf {a} } and b {\displaystyle \mathbf {b} } are the respective directions, and a 0 {\displaystyle \mathbf {a^{0}} } and b 0 {\displaystyle \mathbf {b^{0}} } are an arbitrary point along said lines, respectively. Both the directions and points are vectors, of course.
d ( A , B ) = | ( a 0 − b 0 ) + ( ( a ⋅ b ) ( b ⋅ ( a 0 − b 0 ) ) − ( a ⋅ ( a 0 − b 0 ) ) ) a − ( ( b ⋅ ( a 0 − b 0 ) ) − ( a ⋅ b ) ( a ⋅ ( a 0 − b 0 ) ) ) b 1 − ( a ⋅ b ) 2 | {\displaystyle d(\mathbf {A} ,\mathbf {B} )={\bigg |}(\mathbf {a^{0}} -\mathbf {b^{0}} )+{\frac {((\mathbf {a} \cdot \mathbf {b} )(\mathbf {b} \cdot (\mathbf {a^{0}} -\mathbf {b^{0}} ))-(\mathbf {a} \cdot (\mathbf {a^{0}} -\mathbf {b^{0}} )))\mathbf {a} -((\mathbf {b} \cdot (\mathbf {a^{0}} -\mathbf {b^{0}} ))-(\mathbf {a} \cdot \mathbf {b} )(\mathbf {a} \cdot (\mathbf {a^{0}} -\mathbf {b^{0}} )))\mathbf {b} }{1-(\mathbf {a} \cdot \mathbf {b} )^{2}}}{\bigg |}}