What is the algorithm that Shapely used to check if two polygons intersect?
from shapely.geometry import Polygon
p1 = Polygon([(0,0), (3,0), (3,1), (1,1), (1,2), (3,2), (3,3), (0,3)])
p2 = Polygon([(4,0), (5,0), (5,1.5), (2,1.5), (2,1.2), (4,1.2)])
print(p1.intersects(p2))
I had read the source code of Shapely but didn't find the implementation.
Best Answer
A quick search of the Shapely code base leads to
impl.py
which:So the next place to look is GEOS and
Geometry.ccp
and it'sintersection
method. This is a wrapper forHeuristicOverlay
which calls OverlayNGRobust::overlay which is where we start to see references to JTS, where the API docs state:After some more poking around in the JTS code we eventually come to
RelateComputer
which calculates theIntersectionMatrix
between two geometries (which includes intersection).Any deeper than that and you will need to wait for Dr JTS to answer.