calculate intersection between two segments in a symmetric way

Posted by Elazar Leibovich on Stack Overflow See other posts from Stack Overflow or by Elazar Leibovich
Published on 2010-04-11T05:39:24Z Indexed on 2010/04/11 5:43 UTC
Read the original article Hit count: 305

Filed under:
|
|
|

When using the usual formulas to calculate intersection between two 2D segments, ie here, if you round the result to an integer, you get non-symmetric results.

That is, sometimes, due to rounding errors, I get that intersection(A,B)!=intersection(B,A).

The best solution is to keep working with floats, and compare the results up to a certain precision. However, I must round the results to integers after calculating the intersection, I cannot keep working with floats.

My best solution so far was to use some full order on the segments in the plane, and have intersection to always compare the smaller segment to the larger segment.

Is there a better method? Am I missing something?

© Stack Overflow or respective owner

Related posts about math

Related posts about geometry