Intersection of two line segments involves the following cases:
- Segments are parallel
- Segments are collinear/coincident
- One segment intersects the extension of the other
- Extension of one segment intersects the extension of the other
- Segments intersect each other.
The details of the solution can be found in the CGA FAQ linked above. A C++ implementation can be found here: http://code.google.com/p/curve-project/source/browse/trunk/lab/cgafaq/cgafaq.h The function
cgafaq::intersect takes 4 points — the start and end points of each of the lines. r and s are output parameters calculated as described in the FAQ.
Disclaimer: This post and the code provided are not endorsed by any of the contributors to the CGA FAQ.