ideasman42 / isect_segments-bentley_ottmann

BentleyOttmann sweep-line implementation (for finding all intersections in a set of line segments)
MIT License
91 stars 40 forks source link

two line segments return two intersections #19

Closed ficapy closed 3 years ago

ficapy commented 5 years ago
import poly_point_isect
poly = (
    (140357.2616341884, 11912.20245016317),
    (140392.3460311006, 11911.04283354345),
    (140374.8858468038, 11909.41727425209),
    (140374.8858468038, 12009.41727425209),
    )
isect = poly_point_isect.isect_polygon(poly)

print(isect)
# [(140374.88584680558, 11911.619931099003), (140392.34603099833, 11911.04283354125)]

very strange results, can you explain?

ideasman42 commented 3 years ago

This is a float precision issue, if you use smaller values or increase the internal epsilon to 1e-6 it works.

Another solution is to use the decimal module, set: NUMBER_TYPE = 'decimal' in poly_point_isect.py.

Closing as resolving floating precision errors are outside the scope of this module.