Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two parallel line segments intersection

Tags:

geometry

I know there are many algorithms to verify whether two line segments are intersected.

The line segments I'm talking about are length line constructed by 2 end points.

But once they encountered parallel condition, they just tell the user a big "No" and
pretend there is no overlap, share end point, or end point collusion.

I know I can can calculate the distance between 2 lines segments.
If the distance is 0, check the end points located in the other line segments or not.
And this means I have to use a lot of if else and && || conditions.

This is not difficult, but my question is

"Is there a trick( or mathematics) method to calculate this special parallel case?"

I hope this picture clarify my question
http://judark.myweb.hinet.net/parallel.JPG

like image 545
Judarkness Avatar asked Oct 15 '22 06:10

Judarkness


1 Answers

Yes, given the formulas for both of the lines, test whether their slopes are equal. If they are, the lines are parallel and never intersect.

If you have points on each of the lines, you can use the slope formula.

If both are perpendicular to the x-axis, they will both have infinite slopes, but they will be parallel. All points on each line will have equal x coordinates.

To deal with line segments, calculate the point of intersection, then determine if that point of intersection exists for both of the segments.

like image 64
WhirlWind Avatar answered Oct 18 '22 14:10

WhirlWind