0

I have one main (red) rectangle and several other rectangles, which intersect main rectangle randomly.

How can I get non-intersection area of main rectangle (red area)?

see preview

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
  • If you have the coordinates of each rectangle's four vertices, you can subtract the surface of the parts of each grey rectangle inside the red rectangle from the red rectangle's total surface. That shouldn't be too hard to achieve. – Nelewout Sep 19 '16 at 09:45

1 Answers1

0

This depends very much on what you mean by "have" and "get". What are the input and output formats? Do you want a sequence of points, or just the area? Is this for a general solution, or just this simplified case?

For a fast, general solution, I highly recommend the BOOST polygon library (disclosure: I was one reviewer for the BOOST conference presentation). This handles arbitrary polygons, including holes, and does a lovely job of all the basic polygon operations.

A simple polygon is a sequence of points. You can make sets of polygons. For this case, declare all of your polygons; put the red rectangle into set A, the gray ones into set B. Then A-B returns the desired displayed polygon.

Prune
  • 76,765
  • 14
  • 60
  • 81