Check if two polygons overlap: Difference between revisions

Content added Content deleted
Line 283:
end;
 
# If there's an axis for which the projections do not overlap, then false; else true
def polygonsOverlap($poly1; $poly2):
first any( (($poly1, $poly2) | getAxes[]) as $axis;
. as $axis
| ($poly1 | projectOntoAxis($axis)) as $proj1
| ($poly2poly1 | projectOntoAxis($axis)) as $proj2proj1
| ($poly1poly2 | projectOntoAxis($axis)) as $proj1proj2
| if (projectionsOverlap($proj1; $proj2) | not) then 0 else empty end)
// 1
| .not; == 1;
 
def poly1: [[0, 0], [0, 2], [1, 4], [2, 2], [2, 0]];