1

Provided is a list of tiles (rectangles with different sizes) which are defined by the the points on the diagonal rectangle meaning, that is a list of data such as (x_left_top, y_left_top) ,(x_bottom_right, y_bottom_right).

The tiles compose a bigger polygon and the purpose is to find the border of this polygon. The rectangles can Overlap but only a little (I don't know how to defined, figure is appended).

all the polygon: [ all the polygon][1]

the overlap example the overlap ecample

another example another example

i very appreciate any idea of algorithm to find the edges of the polygon in order to be able to draw its border. best regards, gal

גל אורן
  • 37
  • 1
  • 6
  • Welcome to StackOverflow. To have greater changes of a good answer, please share what you have tried and where specifically are you stuck. Take a look at [ask] to get more tips on how to ask a good question. – Ángela Jul 16 '20 at 07:34
  • Several things here are not entirely clear. First and foremost: What do you want your final answer to look like? Do you want a list of points that define the edges of the polygon, is that it? – Kjartan Jul 16 '20 at 07:47
  • @kjartan yes, order in that way that i can take the edges and draw from them the outline. – גל אורן Jul 16 '20 at 08:26
  • [https://en.wikipedia.org/wiki/Boolean_operations_on_polygons](https://en.wikipedia.org/wiki/Boolean_operations_on_polygons) see the reference to [sweep line algorithms](https://en.wikipedia.org/wiki/Sweep_line_algorithm) – גלעד ברקן Jul 16 '20 at 10:14
  • https://stackoverflow.com/questions/42171051/perimeter-of-union-of-n-rectangles – Photon Jul 16 '20 at 12:32
  • @Photon I looked at this post before i publish my problem but i hard to understand how i use the sweep line algo in order to extract the border and not the are. i would very appreciate your help – גל אורן Jul 18 '20 at 21:46
  • @גלעדברקן i looked at the reference you sent but still don't understand how i do using in sweep line algo for this purpose tnx for your help – גל אורן Jul 18 '20 at 21:46

1 Answers1

0

Here's an outline of a general algorithm without implementation details: sort all the rectangles by their left edge ascending (each x-coordinate that's associated with the left vertical line of the rectangle). Our "sweep-line" will be a vertical line moving to the right.

As we sweep, maintain a structure with current vertical intervals, some of which may be composed from more than one rectangle edge (e.g., B and C). When we encounter the left edge of a rectangle, we add it to the current intervals and update them by appropriately extending or adding to them if needed. When we encounter the right edge of a rectangle, we again update the current intervals, removing parts or whole intervals from our current structure. Each such encounter may reveal more vertical lines that are part of the perimeter (our sought after result). One tricky part is determining which edge parts are concealed by existing intervals and are therefore irrelevant to the perimeter. A second sweep, say top-down with a horizontal line, could provide us with the horizontal lines of the perimeter.

 sweep-line ---->
   |
   | +------+
   | |A     |
   | |   +------+
   | |   |B |   |
   | +------+   |
   |     |      |
   |     +---+--+
   |     |C  |
   |     |   |
   |     +---+
גלעד ברקן
  • 23,602
  • 3
  • 25
  • 61