Closed smichr closed 6 years ago
Hi @smichr casting floats to integers (while not common AFAIK) works as long as the sign is never flipped (see this Q&A)
But I'm not sure what problem this solves exactly, since new intersections need to be calculated, this will need to be done in floating point so the results order correctly on the sweep line ~ any issues with float precision here will still apply.
what problem this solves exactly
I'm thinking from the SymPy perspective where exact values are representing coordinates which may be irrational and complicated. By switching to integers all intersections can be computed (quickly) as rationals and there would be no issues with comparison while computing the interacting segments. Afterwards, the exact intersections can be computed once the interacting pairs are known. So in the example I gave, the exact intersection, (-sqrt(2)/3, 0)
is found rather than a floating approximation.
It's a freshman blunder.
Here's a set of segments in which there is an intersection:
>>> s
[((0, 0), (1/2, 1)), ((0, 9/8), (3, 0)), ((2, 1), (4, 0))]
>>> isect_segments(s)
[(9/19, 18/19)]
When converted to ordinal pts in x and y they become a set of segments in which there is no intersection.
>>> t
[((0, 0), (1, 1)), ((0, 2), (3, 0)), ((2, 1), (4, 0))]
>>> isect_segments(t)
[]
So getting no intersections in the ordinally remapped segments doesn't tell you whether the original set of segments intersected or not.
Is it true that if there is an intersection in the ordinally remapped set that there must have been an intersection in the original set? Nope:
>>> isect_segments([((0, 0), (4, 3)), ((0, 2), (1, 4/5))])
[]
>>> isect_segments([((0, 0), (2, 3)), ((0, 2), (1, 1))])
[(0.8, 1.2)]
Unless the following idea is a freshman geometry blunder, I wonder if it might be useful to simply recast all input to integers (and the user would have to provide a function to convert a segment to a tuple of sortable coordinates). The user would be given, in return, a list of interacting segment indices. Here is an example with SymPy
The steps of the crossing function are to
{It might also make sense to drop the canonicalization step and to just keep track of the coordinates.}