How to test any 2 line segments (3D) are collinear or not? if we have two line segments in 3D, what would be the way to test whether these two lines are collinear or not? (I fogot to mentioned that my line segments are 3D. So, I edited the original post. Sorry for the inconveniences)
I wish to check the direction of the lines and the perpendicular distance between them.
Does these two factors are enough to decide whether 2 line segments are collinear or not.
Thank you in advance.

If the two line segments $AB$ and $CD$ are given by 4 distinct points A, B, C and D, it is also sufficient that both $AB \parallel CD$, $AC \parallel BD$ and $AD\parallel BC$.
To see if $A(a_1,a_2)B(b_1,b_2) \parallel C(c_1,c_2)D(d_1,d_2)$, you test whether or not $\vec{BA} = B-A $ and $\vec{DC} = C-D$ are linearly dependent vectors.
So the two line segments are contained in the same line if
$$ \begin{cases} (a_1-b_1)(c_2-d_2) - (c_1-d_1)(a_2-b_2) = 0 \\ (a_1-c_1)(b_2-d_2) - (b_1-d_1)(a_2-c_2) = 0 \\ (a_1-d_1)(c_2-b_2) - (c_1-b_1)(a_2-d_2) = 0  \end{cases}$$
