How to calculate the area of ​​several overlapping rectangular polygons?

I am looking for a way to calculate common areas covered by several overlapping polygons. Polygons are all rectangular if this helps facilitate the process.

So for example:

   BBBBB
   BBBBB
AAA --- BB
AAA --- BB
AAAAAA
AA - AA
AA - AA
  LL
  LL
  Lllll
  Lllll

I would like to find the total area covered by A, B and L, which will be equal to: B = 5x4 = 20 + A = 6x5 = 30 + L = 4x2 + 6x2 = 20 = 70 minus overlapping areas: - 10 = 60 (total area covered by all polygons)

I need to be able to handle situations where 3 or more polygons occupy the same area. Is there any suitable algorithm for this that can take arrays of x / y coordinate arrays as input? (a sample Java source code would be very welcome).

+3
3

. , .

, .

+2

- . . peasy.

0

2D int bool (A [i] [j] == 1, ijth , 0 ), 2D- .

:

// get your polygons, each represented by a 2D array as described above

// create a "bounding" array B that can contain all polygons (watch out for
// sparsely spaced polygons in which case B could be large)

// populate B s.t. B[i][j] == 1 if ijth slot is contained in 
// the union of all polygons

// count all slots in B where B[i][j] == 1 (this will be the "common" area)

: . B. - (, , ). , ... , , "" - .

0

Source: https://habr.com/ru/post/1717084/


All Articles