Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6795711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:22:47+00:00 2026-05-26T18:22:47+00:00

I come across this math problem which is needed to complete my application, so

  • 0

I come across this math problem which is needed to complete my application, so I’m asking for help.

Given 2 (or more, but basically for 2) rectangles with 2 known points for each: Top-left(x1, y1) and Bottom-right(x2, y2) (I can find the length with these info, if it is a need to solve the problem).

TL(x1, y1)
   +-----------------+
   |                 |
   |                 |       TL(x3, y3)
   |                 |            +---------------------------+
   +-----------------+            |                           |
               BR(x2, y2)         +---------------------------+
                                                         BR(x4, y4)

Is there anyway to determine if they have intersection, in area, I mean, if any part of this rectangle lays on any part of another one?

I’ve searched and found out a little help, but it does not solve the problem:

There are 4 conditions in which the two rectangles will not intersect:

  • The left edge of one rectangle is on the right side of the right edge of the other one, means that the first one is completely laid on the right side of the second one, no intersection.

  • The right edge of one rectangle is on the left side of the left edge of the other one, means that the first one is completely laid on the left side of the second one, no intersection.

  • The top edge of one rectangle is under the bottom edge of the other one, means that the first one is completely laid under the second one, no intersection.

  • The bottom edge of one rectangle is above the top edge of the other one, means that the first one is completely laid above the second one, no intersection.

So I tried to reverse the conditions, which is if 4 of the above does not occur, the rectangles may intersect. But I still can find the condition (such as the picture above) in which 2 rectangles do not fulfill any condition, and still does not intersect.

Any help is highly appreciated, please show me the way to do it or algorithm or code (JS and PHP only please).

Big thank!

[x]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:22:48+00:00Added an answer on May 26, 2026 at 6:22 pm

    An algorithm for the intersection detection (“overlapping”) of any number of
    rectangles could work as follows. Two data structures are used.

    • A sorted list S of the x-coordinates of the left and right edges of the rectangles.
    • An interval tree T of the intervals given by the y-coordinates (bottom/top) of the rectangles.

    The algorithm sweeps over the sorted list S of the x-coordinates:

    1. If the current x-coordinate is the left edge of a rectangle R then
      the y-coordinates [y1, y2] of R are compared to the interval tree T.
      If an overlap is found, then the algorithm stops and reports OVERLAP. If
      there was no overlap in the tree T, then the interval [y1, y2] is
      inserted into the tree.

    2. If the current x-coordinate is the right edge of a rectangle R then
      its y-interval [y1, y2] is removed from the interval tree T.

    3. If the sorted list S is completely processed, then there was no overlap. The algorithm stops and reports NO-OVERLAP.

    The time complexity for N rectangles is O(N*log(N))
    because for each 2*N
    x-coordinates a search in the interval tree for N intervals is performed.
    The space complexity is O(N) for the auxiliary data structures S and T.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I've come across this problem before, but I'm having a bit of
I frequently come across this problem. I have a file: something something2 something3 which
So I've come across this problem and I can't seem to solve it. Basically
I have come across this problem several times in which I would like to
I come across this problem when i am writing an event handler in SharePoint.
I think I've come across this requirement for a dozen times. But I could
I've come across this issue in my application, and have reproduced it using Apple's
I have come across this problem in a calculation I do in my code,
I am asking this here in the hope that someone has maybe come across
Sometimes I come across this problem where you have a set of functions that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.