Assume I have the following overlapping rectangles ("a" and "b"):
aaaaaaaa
aaaaccccbbbbb
aaaaccccbbbbb
aaaaccccbbbbb
bbbbbbbbb
bbbbbbbbb
I've seen lots of ideas on how to calculate the area of the inner rectangle ("c"), but how would I go about getting the actual top/left/bottom/right coordinates for it?
Two rectangles do not overlap if one of the following conditions is true. 1) One rectangle is above top edge of other rectangle. 2) One rectangle is on left side of left edge of other rectangle. We need to check above cases to find out if given rectangles overlap or not.
Overlap = min(A2, B2) - max(A1, B1) + 1. In other words, the overlap of two integer intervals is a difference between the minimum value of the two upper boundaries and the maximum value of the two lower boundaries, plus 1.
If the area of their intersection is positive, two rectangles overlap. Two rectangles that touch at the corners or edges do not overlap. If two axis-aligned rectangles, rec1 and rec2 , overlap, it returns true , otherwise, it returns false .
Call Rectangle.Intersect
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With