intersection between line segments - narrowed precondition I believe that the issue may already have been discussed here. I want to find if two line segments does intersect and if they do then find and store and intesection points. Now it is already confirmed that one of the line segments will always be parallel to x-axis or y-axis. 
So in that case how should we reformulate the basic algorithm that checks the line segments intersection?
The arbitrary line can be expressed as y = a*x+b (assuming it's not parallel to the y axis). 

If the other line is parallel to the y axis then you can simply fill in the x coordinate of any point on the line into the formula of the first line. Then you can check whether they intersect by ensuring the result lies between the endpoints of the second line.

For the second line parallel to the x axis you just flip the x and y coordinates.