Determine whether two rectangles intersect the algorithm

Source: Internet
Author: User
Tags abs

The spatial position of two rectangles (2d) has four cases, as shown in the following figure:


To the two rectangle named a, a, but two rectangular sitting and lower-right coordinate (ax0,ay0), (bx0,by0), according to the judgment of four cases intersect there are four cases, that is, to write four judgments, this is a bit wordy, in fact, according to the four kinds of circumstances can be introduced by the law, as shown below:


This algorithm can be written as

Bx1>ax0,by1>ay1,ax1>bx0,ay1>by0

Here is a JS write example, of course, others, take over to do the proof:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> The results shown are:



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.