math - Calculate overlap between two rectangles on x/y grid? -
I need to calculate overlap (zodiac or yes / no), which is two rectangles on a particular x / y grid Make them. The grid is 500x500 but connected to the side and corner (continuous). Then after 499, the next point becomes 0.
In the last question I asked a way to calculate the distance between the two points in this grid. It turns out to be Euclidean distance:
sqrt (min (| x1 - x2 |, gridwidth - | x1 - x2 |) ^ 2 + min (| y1 - y2 |, gridhight - | Y1-y2 |) ^ 2)
What is the good mathematical way of calculating the two rectangular (one point (x, y), width and height) is the grid Can be overlap in?
Rectangle-1 ( [x = 0, y = 0], w = 20, h = 20
) and rectangle -2 ( [X = 495, y = 0], w = 10, h = 10
) should overlap. Overlapping rectangle (not really necessary) but should be ( [x = 0, y = 0], w = 5, h = 10
)
x1 = x = 0, x2 = x + w = 20 y1 = y = 0, y2 = y + h = 20 is equal to rectangle 2:
x3 = 495, x4 = 505 mod 500 = 5 y3 = 0, y4 Create x and y "regions" for each rectangle:
feedback -1: X-regions: (0, 20) y- Regions: (0, 20) Rectangle-2: X-regions: (495, 500), (0, 5) Y-regions: (0, 10)
If between two rectangles a non-existent in any (both) X and Y areas If there is an intersection, then your rectangles overlap. Here, there is a non-zero crossing in rectangle 1's (0, 20) x-field and rectangle-2 (0, 5) x-field and so (0, 20) and (0, 10) y -regrace.
Comments
Post a Comment