I have a set of N line segments in 3-space where each segment is represented by two coordinates denoting the endpoints of the segment: (x1, y1, z1)-(x2, y2, z2)
I want to know if any line segments are touching, or more formally, if they are:
- intersecting
- partially or fully overlapping
Of course there is the naive search of testing each one against the other in O(N^2) with 2 nested loops, but is there a more efficient algorithm?
Co-linear lines are ok so long as they do not overlap; touching at exactly at the endpoints is acceptable. (This is a sanity for NEC2 because it does not handle wires that touch unless they connect at endpoints. Any that touch but do not touch at endpoints must be broken into multiple wires.)