Check if two polygons overlap: Difference between revisions

Content added Content deleted
Line 283: Line 283:
end;
end;


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


def poly1: [[0, 0], [0, 2], [1, 4], [2, 2], [2, 0]];
def poly1: [[0, 0], [0, 2], [1, 4], [2, 2], [2, 0]];