Search for brute force algorithm to remove overlapping areas of the Rects collection

I have an n-dimensional collection of Rects, most of which intersect. I would like to remove the intersections and reduce the intersecting Rectas by smaller disjoint rectangles.

I could easily redirect the solution, but I am looking for an efficient algorithm.

Here's the visualization:

Original:

original

Processed by:

processed

Ideally, the method signature would look like this:

public static List<RectF> resolveIntersection(List<RectF> rects);

the output will be greater than or equal to the input, where the output permits the aforementioned visual presentation.

+5
source share
3 answers

, . -, , x y . , y . . y.

( , ) , , , , , + . ( )

. , - .

x y , , , .

. R (x1, x2, y1, y2), x1 - , x2 - , y1 - y2 -

rectangle 1 (1,5,0,4) 
rectangle 2 (7,9,6,8)
rectangle 3 (2,4,2,3)
rectangle 4 (3,6,3,7)
rectangle 5 (3,6,9,15)

y1,

#              y1  size
rectangle 1     0   4
rectangle 3     2   3
rectangle 4     3   4
rectangle 2     6   2
rectangle 5     9   6

1 y1 + size = 0 + 4 = 4, , 3 ( y1 = 3 4) 4 ( y1 = 3 4), 2 ( y1 value = 6 > 4)... 2

3 y2 + size = 2 + 3 = 5, , 4 ( y1 = 3 5), recatngle 2 ( y1 = 6 > 5) 2

4 y2 + size = 3 + 4 = 7, , 2 ( y1 = 6 < 7), 5 ( y1 = 9 > 7)

, .

+2

Sweepline . , . , . .

, .

, , , ( N ^ 1.5, N ^ 2).

+6

what you describe is a packaging problem, see wikipedia

he refers to this article describing the algorithm for packing rectangles into rectangles

this is from the article:

This article describes a quick algorithm for packing a series of rectangles of different widths and heights into a single closed rectangle without overlapping and in such a way as to minimize the amount of lost space in the enclosing rectangle.

-2
source

All Articles