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

  • SEARCH
  • Home
  • 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 248263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:19:42+00:00 2026-05-11T21:19:42+00:00

I’ve got two rectangles represented by structures that contain the x1, y1, x2, y2

  • 0

I’ve got two rectangles represented by structures that contain the x1, y1, x2, y2 coordinates. One rectangle can be considered the parent, another the child.

I already know how to detect if the child rectangle is within the parent rectangle; what I’m trying to figure out now is the simplest, fastest way to determine the rectangular areas within the parent that are not being overlapped by the child rectangle.

For example, consider a 100×100 parent rectangle, and a 50×50 child rectangle located exactly in the center of the parent. This would mean there would be four rectangles representing the four areas in the parent rectangle that aren’t being overlapped by the child.

Of course, the child could be in the top left, top right, bottom left, bottom right corner, or a little to the left, a little to the right, etc… there might be one, two, three, or four rectangles that represent the non-overlapped areas.

I’ve had some ideas for implementations to figure this out, but all seem overly complex. Is there a simple, fast way to figure this out?

  • 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-11T21:19:42+00:00Added an answer on May 11, 2026 at 9:19 pm

    So there could be up to 4 rectangles of non-overlapped area. Let’s make a list of them.

    leftrect = rightrect = toprect = bottomrect = None
    trimmedparent = duplicate(parent)
    
    if parent.x1 < child.x1:
        leftrect = duplicate(parent)
        leftrect.x2 = child.x1
        trimmedparent.x1 = child.x1
    
    if parent.x2 > child.x2:
        rightrect = duplicate(parent)
        rightrect.x1 = child.x2
        trimmedparent.x2 = child.x2
    
    if parent.y1 < child.y1:
        toprect = duplicate(trimmedparent)
        toprect.y2 = child.y1
    
    if parent.y2 > child.y2:
        bottomrect = duplicate(trimmedparent)
        bottomrect.y1 = child.y2
    

    The only tricky part is eliminating the part where e.g leftrect and toprect might intersect. I used ‘trimmedparent’ as an intermediate step to trim that section from toprect.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm making a simple page using Google Maps API 3. My first. One marker
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.