Coders Packet

Check if two given lines intersect or not in C++

By Amit Kumar

If lines intersect with each other then we print the message that lines intersect with each other along with coordinates and if not then we print that the lines do not intersect with each other.

In this project, we finding that if lines intersect with each other or not, if they intersect with each other then simply we print the message that lines intersect with each other along with coordinates and if not then we print that the lines do not intersect with each other.

There are three valid cases for the intersection of two lines.

Case 1:

Both line intersect with each other properly

In this figure, you can see that both lines intersect with each other properly. p2q2p1 is in the anticlockwise direction and p2q2q1 is in the clockwise direction.

case 2:

One line touching other line

In this figure, you can see that p1 is colinear to p2 and q2 and p2q2q1 is in the clockwise direction.

Case 3:

Colinear lines

In this case, both lines are colinear to each other but they are touching with each other at some point.

From seeing the above cases we can say that both line segments are intersecting when these cases are satisfied:

1. When (p2,q2,p1) and (p2, q2, q1) have a different orientation.

2. If lines are colinear they should touch with each other at some point.

Download project

Reviews Report

Submitted by Amit Kumar (amit25)

Download packets of source code on Coders Packet