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?
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".