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.
How to test any 2 line segments (3D) are collinear or not?
-
0@Michael Chen: thank you – 2012-02-03
4 Answers
An alternative method. Assume $PQ$ and $RS$ are the line segments. Let the direction cosines of the vectors $\mathbf{u=} \overrightarrow{PQ}$ and $\mathbf{v=}\overrightarrow{RS}$ be, respectively, $ \alpha _{u},\beta _{u},\gamma _{u}$ and $\alpha _{v},\beta _{v},\gamma _{v}$. The angle $\phi $ between the line segments is such that$^{1}$ $ \begin{equation*} \cos \phi =\alpha _{u}\alpha _{v}+\beta _{u}\beta _{v}+\gamma _{u}\gamma _{v}. \end{equation*} $
Hence the line segments are collinear if $\cos \phi =\pm 1$.
--
$^{1}$Formula 10.7 of Manual de Fórmulas e Tabelas Matemáticas, Coleção Schaum, Portuguese translation of Schaum's Outline Series Mathematical Handbook of Formulas and tables, 2/e by Murray Spiegel and John Liu.
-
0@g_niro: You are welcome! – 2012-01-28
Yes, those two factors are enough. For the segments to be collinear, first their directions must be the same, and next their perpendicular distance must be zero.
Alternatively, if you have the first condition, you just need that they have $one$ point in common
You can write the equation of one line and check to see if both endpoints of the other lie on it.
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}$
-
0@g_niro: then you project onto the $XY$ and $XZ$ planes and check if the projections onto these planes are colinear. (This is equivalent to saying that two vectors $(a,b,c)$ and $(x,y,z)$ are parallel iff \begin{vmatrix}b&c\\y&z\end{vmatrix} = \begin{vmatrix}a&c\\x&z\end{vmatrix} = 0 – 2012-01-27