6

Im trying to find an algorithm for drawing a common outline between multiple polygons. What I mean is like on this picture:

two polygons to find outline

We have two rectangles (In my case they will not be rectangles, but polygons with most of their angles as right angle) and Im looking for common outline like a red path on second part of image. The biggest problem as I see it is finding new points which I marked yellow on the second part of image. The polygons will never intersect or touch itselfs. Im storing a polygon as points in counter-clockwise order.

Im looking for some clues, sources or even keywords on which I should google, which could make my task little easier...

EDIT: its kind like in convex hull but looking at the edges not at the vertices, yellow point are probably on the continuaion of the edges as I look at it.

EDIT2: Ok, I need to draw a border of given size around polygons, but in such way that if two polygons are closer than the border size they will have common border which is kind of a sum of two borders without 'inner' part of it and this two polygons will be treated as a one shape. So Im trying to find this red polygon which will be used to draw this border around it.

Pax0r
  • 2,324
  • 2
  • 31
  • 49
  • Not exactly what you asked for, but perhaps the [convex hull](http://en.wikipedia.org/wiki/Convex_hull) would suffice. [Many algorithms](http://en.wikipedia.org/wiki/Convex_hull_algorithms) exist to calculate that. – hammar Jul 10 '11 at 11:56
  • Yes, I was looking at convex hull algorithms but this make a jump from the vertex of one polygon to another, not preserving edges like I need it to. – Pax0r Jul 10 '11 at 11:58
  • 1
    Where do you want to put the yellow points? It looks rather arbitrary what you did it in your example. Can you give a clear specification of what you want to have, i.e. what is "a common outline". – Howard Jul 10 '11 at 12:02
  • @Howard: it looks like the OP needs our help making the clear specification in the first place. – Gareth Rees Jul 10 '11 at 12:26
  • @Gareth True, but after the edit I am even more confused about what OP *really* wants to do. I still do not get what the properties of the red outline should be. – Howard Jul 10 '11 at 12:51
  • @Pax0r Maybe you can give us some background: *What* are the polygons representing? Which is the *original problem* you try to solve? *Why* do you need a common outline? – Howard Jul 10 '11 at 12:59
  • 1
    @Pax0r An appropriate algorithm would be to grow each polygon by the border size and join the larger polygons into one (if they overlap). Afterwards you can shrink the new polygon again by the same amount if you like. – Howard Jul 10 '11 at 14:32

2 Answers2

3

Start by adding extra vertices to your polygons (your yellow ones) by clipping all edges against all other edges extended to infinity (e.g. turn your edges into infinite lines).

Connect the new vertices to the extended edges. This will give you a polygonal mesh.

Now comes the trick:

Start-condition:

  • Pick the most top-left vertex, there can be only one!

  • Pick the edge with the least slope that connects to the vertex found by 1 and extends to the right. This edge will always be on the perimeter of your final polygon.

Iteration:

  • From your current edge, walk along the other edges in clockwise order. You will encounter new vertices as you do this, and these vertices may connect to multiple other edges. Always pick the most counter-clockwise one and continue. This will always keep you on the perimeter of your final polygon.

End Condition:

  • Stop as soon as you reach the top-left vertex again.

Congratulations, you just walked around the outer edge of your polygon.

Nils Pipenbrinck
  • 83,631
  • 31
  • 151
  • 221
  • Your algorithm seems as exactly want I need but I have problem how to pick 'most counter-clockwise' vertex... – Pax0r Jul 13 '11 at 12:27
0

I'd look for "best-fit bounding box" as in http://www.comp.nus.edu.sg/~tancl/Papers/DAS06/39-oyuanbuusu.pdf and of course, the bibliography of that, recursively.

msw
  • 42,753
  • 9
  • 87
  • 112
  • Thank you for this answer. It seems that link does not work any more. Could you maybe give the DOI or title & author and/or update the link? I know its been seven years, but I'd still be interested. – 3244611user Sep 20 '18 at 16:09