Set Rectangle A (XA1,YA1), (XA2,YA2), B (Xb1,yb1), (XB2,YB2)of which: XA1<=XA2,YA1<=YA2XB1<=XB2,YB1<=YB2
First look at the intersection of the line of judgment: La:xa1,xa2 Xa1<=xa2lb:xb1, Xb2 Xb1<=xb2 consider the opposite (only two cases): Disjoint condition: xa2<xb1| | Xa1>xb2by Morgan Law, the intersection condition is drawn: Xa2>=xb1&&xa1<=xb2
The conditions for the intersection of rectangle a B are: the projections intersect on the X and Y axes, respectively. That is: on the x axis, the line intersection condition, there is xa2>=xb1 (1) Xa1<=xb2 (2) and Xa1<=xa2 (3) Xb1<=xb2 (4)
(1), (3) <=> Xa2>=max (XA1,XB1);(2), (4) <=> Xb2>=max (XA1,XB1); min (Xa2,xb2) >=max (XA1,XB1); Similarly: min (ya2,yb2) >=max (YA1,YB1), so the intersection condition is:min (xa2,xb2) >=max(XA1,XB1) &&min (ya2,yb2) >=max(ya1,yb1) among them:XA1<=XA2,YA1<=YA2xb1<=xb2,yb1<=yb2
A super-simple method for determining the intersection of rectangles