Reputation: 11
I am drawing a polygon for the Traveling Salesman problem, and would like to test for non-intersection of any paths, as a means of adaptively halting the genetic search. I tried simply checking line segments or intersection, but sometimes I get an incorrect result, terminating the search even though one or more intersections remain.
Upvotes: 1
Views: 142
Reputation: 16007
This problem is essentially equivalent to detecting intersections in an arbitrary set of line-segments.
For example, the bentley-ottmann algorithm can be used to solve this problem. Of course, you can terminate as soon as you find one intersection.
A naive check would just check every edge versus every other edge (that is not adjacent in the polygon, because those cannot intersect), but since you just need to find one intersection, the output-sensitive algorithms (like bentley-ottmann) can speed up your check quite a lot.
Upvotes: 1