• Customer Support: admin@thealgorists.com
  • Feedback: We are listening to your every feedback, and taking action to constantly improve your learning experience. If you have any feedback, please use this form: https://thealgorists.com/Feedback.






In this article, we will see how Sweep Line Technique can be used to compute union of rectangles.



Let's suppose a list of (axis-aligned) rectangles and each rectangle is represented as [x1, y1, x2, y2] , where (x1, y1) are the coordinates of the bottom-left corner, and (x2, y2) are the coordinates of the top-right corner of the ith rectangle.
Our objective is to find the total area covered by all rectangles in the plane.



This problem can be solved very easily using Sweep Line technique, using the concepts of events and active events. However, to solve this problem we would need Dual Sweep Line Technique, where we will have to sweep line along both x-axis and y-axis. The algorithm and code below explains the technique very well.

In-depth Algorithm Discussion and Code Implementation:



This is a Premium Content.
Please subscribe to Algorithms course to access the solution.






Related Must-Read Topics:

  1. 1d Range Search
  2. Closest Pair
  3. Convex Hull
  4. 2D Intervals Union
    & Skyline Problem
  5. Overlapping 1D Intervals
  6. Merging Overlapping 1D Intervals
  7. Separating Overlapping 1D Intervals


The above content is written by:

Abhishek Dey

Abhishek Dey

A Visionary Software Engineer With A Mission To Empower Every Person & Every Organization On The Planet To Achieve More

Microsoft | University of Florida

View LinkedIn profile


If you have any feedback, please use this form: https://thealgorists.com/Feedback.




Subscribe to Our Youtube Channel

Follow Us On LinkedIn
wave