When two polygons have nearly overlapping segments it is impossible to compute their intersecting polygon.
The example below shows that we can test if the two polygons intersect but when we ask to compute the intersecting polygons the code is stuck. It does not even throw up an error.
import numpy as np
import matplotlib.pyplot as plt
import os,sys
sys.path += ["./spherical_geometry"]
from spherical_geometry import polygon
# Large Cell
lc_lons=[2.1145180961198093, 2.2167924672941695, 2.2166355474157626, 2.1142279214148516, 2.1145180961198093]
lc_lats=[45.59579076517927, 45.595946981135235, 45.66751087193568, 45.66735444850059, 45.59579076517927]
lc_cent=[2.1655435080610346, 45.6316621889731]
#Small Cell
sc_lons=[2.200007549639062, 2.2166742168709477, 2.2166742168709477, 2.200007549639062, 2.200007549639062]
sc_lats=[45.66666615789904, 45.66666615789904, 45.649999491515025, 45.649999491515025, 45.66666615789904]
sc_cent=[2.208341, 45.658333]
lc=polygon.SphericalPolygon.from_lonlat(lc_lons, lc_lats, center=lc_cent)
sc=polygon.SphericalPolygon.from_lonlat(sc_lons, sc_lats, center=sc_cent)
plt.plot(sc_lons, sc_lats, c="r")
plt.plot(sc_cent[0], sc_cent[1], marker="x", c="r")
plt.plot(lc_lons, lc_lats, c="g")
plt.plot(lc_cent[0], lc_cent[1], marker="x", c="g")
plt.show()
print("Is there an intersection ? ", lc.intersects_poly(sc))
inter=lc.intersection(sc)
print("Area of intersection :", inter.area())
It is sufficient to shift one of polygons slightly to get it working again ... but then obviously the overlapping area is wrong !
I hope this description of the bug helps solve it.
When two polygons have nearly overlapping segments it is impossible to compute their intersecting polygon.
The example below shows that we can test if the two polygons intersect but when we ask to compute the intersecting polygons the code is stuck. It does not even throw up an error.
It is sufficient to shift one of polygons slightly to get it working again ... but then obviously the overlapping area is wrong !
I hope this description of the bug helps solve it.