Find total area of overlapping rectangles | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Find total area of overlapping rectangles

Suppose a set of rectangles, each of them has sides parallel with x and y axis and is given by the coordinates of opposite points. How to effectively calculate the total area they cover? If two or more share the same piece of area, it is counted only once. I've read that it is called Klee's measure problem and it should be solved using a sweep line and a segment tree which should track the covered parts of plane currently under the sweep line. However, I don't know how should the update of this segment tree be done (for example, if you remove a large rectangle overlapping many smaller ones). Does anybody know how to do this? Thanks for help.

22nd Apr 2019, 6:16 PM
michal
2 Answers
+ 2
Diego That doesn't quite solve this problem, it's something a bit different
25th Apr 2019, 4:47 PM
michal
0
Not sure how to answer your question. Found a similar one on SO. It has a pretty good explanation of the Bentley-Ottmann algorithm. https://stackoverflow.com/q/10049454
24th Apr 2019, 8:22 PM
Diego
Diego - avatar