Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get overlapping rectangle coordinates

Tags:

c#

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?

like image 570
Chris Avatar asked Jul 03 '10 22:07

Chris


People also ask

How do you find the overlap of a rectangle?

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.

How do you find overlap?

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.

Are two rectangles overlapping?

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 .


1 Answers

Call Rectangle.Intersect.

like image 157
Tim Robinson Avatar answered Oct 02 '22 10:10

Tim Robinson