I need to calculate the overlap (amount or yes/no) that two rectangles make on a special x/y grid. The grid is 500x500 but the sides and corners connect (are continuous). So the next point after 499 becomes 0 again.
In a previous question I asked for a way to calculate the distance between two points in this grid. This turned out to be the Euclidean distance:
sqrt(min(|x1 - x2|, gridwidth - |x1 - x2|)^2 + min(|y1 - y2|, gridheight - |y1-y2|)^2)
What is the good mathematical way of calculating if two rectangles (defined by a point (x,y), width and height) have overlap in this grid?
Rectangle-1 ([x=0,y=0], w=20, h=20
) and Rectangle-2 ([x=495,y=0], w=10, h=10
) should have overlap. The overlapping rectangle (not really needed but) should be ([x=0,y=0], w=5, h=10
)