if four points are given in a plane (for two lines) what is the best method to find out if lines are intersecting or not? Any tips on building the algorithm would be highly appreciated since I have no clue about where to begin!
Thanks for the reply. And I'm sorry that I could not mention that any intersection between given two points should be only considered. Any idea?
I don't understand that.
The bottom line is very simple: 2 lines will never intersect only if they are parallel to each other. Being parallel means both lines have the same slope. You just need to verify that the intersect is different just to ensure you are talking about 2 different lines, not just one.
'Point' is typedef'd as sf::Vector2<double>. If you aren't using SFML, you can write your own such class. It's just a class with x,y members, and overloaded operators.
LineCollision will return true if the lines intersect. If they do intersect, and if 'out' is provided, 'out' will be set to the point of collision along line B (scaled 0-1). To get the exact point of intersection, you can do this: