Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question
    
That should do it. If the directions are the same, and the perpendicular distance is zero, they are the same line. –  Michael Chen Jan 27 '12 at 20:05
    
@Michael Chen: thank you –  niro Feb 3 '12 at 0:24
add comment

4 Answers

up vote 3 down vote accepted

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.

share|improve this answer
    
thaank you for the answer. –  niro Jan 28 '12 at 11:02
    
@g_niro: You are welcome! –  Américo Tavares Jan 28 '12 at 12:49
add comment

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

share|improve this answer
add comment

You can write the equation of one line and check to see if both endpoints of the other lie on it.

share|improve this answer
add comment

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}$$

share|improve this answer
    
sorry, i fogot to tell you, my line segments are 3D. –  niro Jan 27 '12 at 22:14
    
@g_niro: Please add that information to your question. I deleted an answer valid for 2D only. –  Américo Tavares Jan 27 '12 at 22:23
    
@g_niro: Thanks! –  Américo Tavares Jan 27 '12 at 22:41
    
@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$ –  Myself Jan 27 '12 at 23:42
    
@Myself: thank you –  niro Jan 28 '12 at 11:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.