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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:36:54+00:00 2026-05-10T18:36:54+00:00

My situation Input: a set of rectangles each rect is comprised of 4 doubles

  • 0

My situation

  • Input: a set of rectangles
  • each rect is comprised of 4 doubles like this: (x0,y0,x1,y1)
  • they are not ‘rotated’ at any angle, all they are ‘normal’ rectangles that go ‘up/down’ and ‘left/right’ with respect to the screen
  • they are randomly placed – they may be touching at the edges, overlapping , or not have any contact
  • I will have several hundred rectangles
  • this is implemented in C#

I need to find

  • The area that is formed by their overlap – all the area in the canvas that more than one rectangle ‘covers’ (for example with two rectangles, it would be the intersection)
  • I don’t need the geometry of the overlap – just the area (example: 4 sq inches)
  • Overlaps shouldn’t be counted multiple times – so for example imagine 3 rects that have the same size and position – they are right on top of each other – this area should be counted once (not three times)

Example

  • The image below contains thre rectangles: A,B,C
  • A and B overlap (as indicated by dashes)
  • B and C overlap (as indicated by dashes)
  • What I am looking for is the area where the dashes are shown

–

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAA--------------BBB AAAAAAAAAAAAAAAA--------------BBB AAAAAAAAAAAAAAAA--------------BBB AAAAAAAAAAAAAAAA--------------BBB                 BBBBBBBBBBBBBBBBB                 BBBBBBBBBBBBBBBBB                 BBBBBBBBBBBBBBBBB                 BBBBBB-----------CCCCCCCC                 BBBBBB-----------CCCCCCCC                 BBBBBB-----------CCCCCCCC                       CCCCCCCCCCCCCCCCCCC                       CCCCCCCCCCCCCCCCCCC                       CCCCCCCCCCCCCCCCCCC                       CCCCCCCCCCCCCCCCCCC 
  • 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. 2026-05-10T18:36:54+00:00Added an answer on May 10, 2026 at 6:36 pm

    An efficient way of computing this area is to use a sweep algorithm. Let us assume that we sweep a vertical line L(x) through the union of rectangles U:

    • first of all, you need to build an event queue Q, which is, in this case, the ordered list of all x-coordinates (left and right) of the rectangles.
    • during the sweep, you should maintain a 1D datastructure, which should give you the total length of the intersection of L(x) and U. The important thing is that this length is constant between two consecutive events q and q’ of Q. So, if l(q) denotes the total length of L(q+) (i.e. L just on the rightside of q) intersected with U, the area swept by L between events q and q’ is exactly l(q)*(q’ – q).
    • you just have to sum up all these swept areas to get the total one.

    We still have to solve the 1D problem. You want a 1D structure, which computes dynamically a union of (vertical) segments. By dynamically, I mean that you sometimes add a new segment, and sometimes remove one.

    I already detailed in my answer to this collapsing ranges question how to do it in a static way (which is in fact a 1D sweep). So if you want something simple, you can directly apply that (by recomputing the union for each event). If you want something more efficient, you just need to adapt it a bit:

    • assuming that you know the union of segments S1…Sn consists of disjoints segments D1…Dk. Adding Sn+1 is very easy, you just have to locate both ends of Sn+1 amongs the ends of D1…Dk.
    • assuming that you know the union of segments S1…Sn consists of disjoints segments D1…Dk, removing segment Si (assuming that Si was included in Dj) means recomputing the union of segments that Dj consisted of, except Si (using the static algorithm).

    This is your dynamic algorithm. Assuming that you will use sorted sets with log-time location queries to represent D1…Dk, this is probably the most efficient non-specialized method you can get.

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

Sidebar

Ask A Question

Stats

  • Questions 81k
  • Answers 82k
  • 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 Collection is also the supertype of List, Queue, Deque, and… May 11, 2026 at 4:34 pm
  • Editorial Team
    Editorial Team added an answer Have the first 50 (or whatever) characters of the field… May 11, 2026 at 4:34 pm
  • Editorial Team
    Editorial Team added an answer If I read it correctly... then the problem is that… May 11, 2026 at 4:34 pm

Related Questions

UPDATE 2009-05-21 I've been testing the #2 method of using a single network share.
We are writing a search application that saves the search criteria to session state
I have a situation where I am using wpf data binding and validation using
My question is similar to Engram's here , but my question goes a bit

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.