I am writing a function to find the intersection of a pair of lines and another function to find the intersection of a pair of line segments. The parallel case and the single point intersection case are logically clean and my functions work well to find these. But, the cases where the lines are collinear or the line segments are collinear and overlapping is logically sloppy (at least in my mind)... Here's how I've approached the problem:
Parallel returns:
NULL (e.g. no intersection)
Point intersection returns:
a Coordinate (e.g. a point)
Collinear line segments that have a single common point returns:
a Coordinate (e.g. the common endpoint)
Collinear line segments that have multiple common points returns:
a Coordinate pair (e.g. the line segment of overlap)
Collinear lines returns:
the furthest separated pair of Coordinates (e.g. the largest line segment definable using any of the points that defined the lines being compared)
Logically in any collinear intersection situation it seems reasonable to just return any point within the overlapping region - it also seems to be reasonable to return every point in the overlapping region - it also seems reasonable to return no points at all (the argument being that collinear intersection is an illogical concept assuming the definition that line / line segment intersection is a single point). If I were to take the approach of returning every point of overlap I would not be able to represent the collinear line intersection case (X and Y would need to have infinity or zero values because there are no endpoints to the intersecting region)...
Briefly researching on the Internet I didn't find a clear-cut definition of collinear intersection - this indicates that I'm treading in the territory of the illogical... Nonetheless, I find it misleading to claim via the functions that I am writing that collinear line segments do not intersect... when I consider the case of determining whether or not a pair of rectangles that share a common collinear line segment intersect... certainly rectangles that share a portion of an edge are intersecting (aren't they)... or (broadening my thinking) is the argument that the rectangles are touching but not intersect... (is touching a standard geometric concept that's differentiated from intersection?) If touching is a differentiated concept then the situation of shared endpoint intersection of line segments is invalid (e.g. there is no intersection of the line segments, but there is touching of the line segments)...
So...
Is collinear intersection a well defined planar geometry concept?
If so, please point me to a reference so that I can absorb the definition and logic behind the definition.
If not, please comment on the approach that I'm following to validate it or provide a more effective way of thinking about these concepts.
Thanks!
A segment is a set of points from the space. The intersection of two sets $A$ and $B$ is defined as $A \cap B = \{x:x\in A \;\wedge\; x\in B \}.$
If you have 2 segments overlapping, why would you need to return something? I would associate each line or segment to a vector containing the slope and the shift about one coordinate axis of the given segment or line. The vector could also contain the endpoints of the segments.
Now, you would need to check if a segment is overlapping with another segment and then return the endpoints of a new segment defined as the intersection of the first two segments. This will be easy if the vectors contain the endpoints' coordinates.