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 568209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:09:52+00:00 2026-05-13T13:09:52+00:00

I need to calculate the overlap (amount or yes/no) that two rectangles make on

  • 0

I need to calculate the overlap (amount or yes/no) that two rectangles make on a special x/y grid. The grid is 500×500 but the sides and corners connect (are continuous). So the next point after 499 becomes 0 again.

In a previous question I asked for a way to calculate the distance between two points in this grid. This turned out to be the Euclidean distance:

sqrt(min(|x1 - x2|, gridwidth - |x1 - x2|)^2 + min(|y1 - y2|, gridheight - |y1-y2|)^2)

What is the good mathematical way of calculating if two rectangles (defined by a point (x,y), width and height) have overlap in this grid?

Rectangle-1 ([x=0,y=0], w=20, h=20) and Rectangle-2 ([x=495,y=0], w=10, h=10) should have overlap. The overlapping rectangle (not really needed but) should be ([x=0,y=0], w=5, h=10)

  • 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-13T13:09:53+00:00Added an answer on May 13, 2026 at 1:09 pm

    First, compute the x and y range for each rectangle
    (because you have a torus geometry do it mod gridsize).

    So, given your Rectangle-1, compute:

    x1 = x = 0, x2 = x + w = 20
    y1 = y = 0, y2 = y + h = 20
    

    Same for Rectangle-2:

    x3 = 495, x4 = 505 mod 500 = 5
    y3 = 0,   y4 = 10
    

    Create the x and y “regions” for each rectangle:

    Reactangle-1: x-regions: (0, 20)
                  y-regions: (0, 20)
    
    Rectangle-2:  x-regions: (495, 500), (0, 5)
                  y-regions: (0, 10)
    

    If any (both) x and y regions between the two rectangles have a non-null intersection, then your rectangles overlap.
    Here the (0, 20) x-region of Rectangle-1 and the (0, 5) x-region of Rectangle-2 have a non-null intersection and so do the (0, 20) and (0, 10) y-regions.

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

Sidebar

Ask A Question

Stats

  • Questions 273k
  • Answers 273k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Updated with regular expression solution implemented in JS. You can… May 13, 2026 at 2:09 pm
  • Editorial Team
    Editorial Team added an answer No you will not be able to do the above.… May 13, 2026 at 2:09 pm
  • Editorial Team
    Editorial Team added an answer fl.data.DataProvider is a Flash authoring tool specific class and cannot… May 13, 2026 at 2:09 pm

Related Questions

I've been programming the iphone for a couple of months now and have 3
I wrote a drawing function that draws various on-screen sprites. These sprites can only
Edit: Simple code I used to solve the problem in case anyone is interested
I'm looking into writing a simple synchronization ability into my app and one of
I need to calculate the time complexity of the following code: for (i =

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.