Decide Whether Two Lines Are Parallel

Decide Whether Two Lines Are Parallel
$\begingroup$

I have two lines which I´d like to know whether they are parallel or not in 3D space. Each line is defined using two points $(x_1,y_1,z_1)$,$(x_2,y_2,z_2)$. Important condition is that there should be a slight rotation threshold allowed, i.e. if the angle between the two lines is < 5 degrees then they are still parallel.

My idea is to compare the slopes of the two line segments somehow? Another way is to find the direction/normal of the line segment, and compare the two directions using the dot product

Any hints?

$\endgroup$
1

3 Answers

$\begingroup$

Create vectors pointing along each line by computing $(x_2,y_2,z_2)-(x_1,y_1,z_1)$ for both pairs. Make them into unit vectors by dividing them by their lengths. Call these two unit vectors $u$ and $v$.

Then you can use the inner product identity: $\langle u,v\rangle=\cos(\theta)$, where $\theta$ is the angle between the two vectors.

You want to create two small thresholds around 1 and -1. When the dot product is close to 1, this means that the vectors are very nearly pointing in the same direction, and when the dot product is nearly -1, they are very close to pointing in opposite directions. In both cases, they are "nearly parallel".

$\endgroup$
$\begingroup$

Natural approaches would be to find two vectors $\vec{a}, \vec{b}$ on the lines ant then either check $\Big|\frac{\vec{a} \cdot \vec{b}}{|\vec{a}| |\vec{b}|}\Big| > \cos \epsilon$ or $\Big|\frac{\vec{a} \times \vec{b}}{|\vec{a}| |\vec{b}|}\Big| < \sin \epsilon$, where $\cdot$ is the dot product, $\times$ is the cross product and $\epsilon$ is the angle of error.

$\endgroup$
5
$\begingroup$

You can also do this using direction cosines. A vector is defined as r= x i + y j + z k. The direction cosines of r are l=cosα= x/|r|, m=cosβ=y/|r| n=cosγ=z/|r|. Find direction cosines for both vectors and if the direction cosines are equal, then you've just proved the lines are parallel.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.