A super-simple method for determining the intersection of rectangles

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.