-1

I have a 2-dimensional array of bool like this

2-dimensional array of bool

The shape won't have any holes -- even if it has -- I'll ignore them. Now I want to find the Polygon embracing my shape:

embracing polygon

Is there any algorithm ready to use for this case? I couldn't find any, but I'm not sure whether I know the correct search-term for this task.

user2033412
  • 1,950
  • 2
  • 27
  • 47
  • It looks to me as if you have found the polygon. But perhaps you could explain a bit more about what you have and what you want. How is your array represented ? What representation do you want for the polygon you are trying to find ? – High Performance Mark Sep 16 '13 at 13:50
  • I found the polygon manually, but I want my program to find it. I would like to find a list of x-y-coordinates representing the polygon. – user2033412 Sep 16 '13 at 14:07
  • 1
    Since you have the coordinates of the included squares the answer to this question -- http://stackoverflow.com/questions/17862162/sort-anticlockwise-the-points-of-rectilinear-polygon#comment26081406_17862162 -- will get you the rest of the way. – High Performance Mark Sep 17 '13 at 09:21

2 Answers2

0

You can use a delaunay triangulation and then remove the longest edges. I use the average of all edges multiply with a constant.

Micromega
  • 12,486
  • 7
  • 35
  • 72
  • delaunay-triangulation is O(n*log(n)) which I think is too expensive for my task. I bet there is a O(n)-way to do it. – user2033412 Sep 16 '13 at 14:24
-1

After thinking about more a little I found it out and there is a O(n)-way to do it: Search row-wise for the first coordinate that contains at least one adjacent field set true. From there you can definitly take the first step to the right. From now on just walk around the field deciding what direction to walk next based on the four adjacent fields.

user2033412
  • 1,950
  • 2
  • 27
  • 47