3

I've implemented the Bentley-Ottmann algorithm and also handled the edge cases mentioned here: http://en.wikipedia.org/wiki/Bentley%E2%80%93Ottmann_algorithm#Special_position_and_numerical_precision_issues.

However, it still doesn't work with all line segments, for example with this one, where only the left intersection is found, but not the second (first 2 lines to the left are inverted in sweep lines dictionary when the first intersection is extracted as event from event priority queue):enter image description here

Or in a bit complicated case, where still only the first intersection from left is recognized:enter image description here

What should I add to the algorithm or change it to also take into consideration this kind of a case (and of course maintain its O(n log n) complexity)?

EDIT: Another "dirty" example, this time no intersections are found:

enter image description here

EDIT 2: See algorithm pseudo code and simulation here from page 28 onwards: http://www-ma2.upc.es/vera/wp-content/uploads/2012/10/intersection-of-segments.pdf

user2340939
  • 1,791
  • 2
  • 17
  • 44
  • Why the downvote? This is theoretical question, thats why no code is posted. – user2340939 May 19 '15 at 19:21
  • Actually it doesn't, just try and get the intersections for the first image on paper, according to the algorithm (should be fast enough). You can follow the following pseudo code: http://geomalgorithms.com/a09-_intersect-3.html. I'm certain my implementation is correct, because I haven't seen such edge case in connection with this algorithm nowhere on the internet. – user2340939 May 19 '15 at 19:44
  • 1
    Just guessing - did you remember to test for intersections after processing the first crossing event point in the first situation? – zw324 May 19 '15 at 19:53
  • By the algorithm, not needed at this this exact event. Look at the "Else" statements of section "Pseudo-Code: Bentley-Ottmann Algorithm" at http://geomalgorithms.com/a09-_intersect-3.html, which is processing the crossing event. – user2340939 May 19 '15 at 20:07
  • `If (I = Intersect(segE2 with segA) exists) If (I is not in EQ already) Insert I into EQ;` Isn't that checking the crossing after the swap? – zw324 May 19 '15 at 20:36
  • Yes of courseit does, but look at this situation: the first two segments are swapped, and then we need segment below the previously lower intersection segment and we also need a segment above the previously upper segment, but both of them are not available (only 3 segments), so there is no intersection checking in the first crossing event point. – user2340939 May 19 '15 at 22:27
  • I think your problem is not in the crossing event, since at that point you have not see the next segment. So the problem should be when you insert the third segment, then you need to check if it intersects the segment above and if it intersects the segment bellow. For the examples I think you may have an issue with the data structure for maintaining the segment ordering with respect to the sweep-line. It looks like you are not finding the segments above and bellow or you are skipping the check somehow. – Javier Cano May 20 '15 at 14:30
  • Also, after a crossing you need to update SL, but considering the last example, it might not be your problem. That is what my intuition suggest, but if you don't show your actual code I can't tell more, the pseudocode doesn't get into details of the data structures, but it seems like a problem with the implementation and handling of SL. Have you tried to debug your code and see what is SL returning each time you ask for the segments above and bellow? – Javier Cano May 20 '15 at 14:37
  • When a crossing event is encountered, I get the above and below segments of the crossing (the upper being the one that has higher left endpoint). Then I switch their positions in SL. Than I check for intersection betweeen the lower crossing segment (which is now the upper one in the SL) and (now ) its upper SL neighbour segment. I do the same for the upper crossing segment (which is now the lowe one in the SL) and (now) its lower SL neighbour segment. I've done plenty of debugging so it works as decribed. – user2340939 May 20 '15 at 15:51
  • But note that problem can be seen in the theory itself, so either I understood the theory/pseudo code wrongly or the theory has flaws. – user2340939 May 20 '15 at 15:52
  • But it seems I had understood it correctly, just see the algorithm simulation here from page 71 onwards, where a crossing event is encountered: http://www-ma2.upc.es/vera/wp-content/uploads/2012/10/intersection-of-segments.pdf. – user2340939 May 20 '15 at 15:58

0 Answers0