3

I'm using the centroid of polygons to attach a marker in a map application. This works definitely fine for convex polygons and quite good for many concave polygons.

However, some polygons (banana, donut) obviously don't produce the desired result: The centroid is in these cases outside the polygons area.

Does anybody know a better approach to find a suitable point within any polygons area (which may contain holes!) to attach a marker?

enter image description here

Disclaimer: This is a cross-post from stackoverflow. I was recommended to re-post it here.

Blue
  • 75,673
  • 4
    Try the point at maximum distance from the boundary. –  May 29 '18 at 16:00
  • 1
    I seem to recall a question here from not-too-long ago (a couple of months?) that asked about placing labels inside regions. A comment or answer described a strategy used by map-makers. I'm having trouble finding that question at the moment. – Blue May 29 '18 at 16:06
  • @Rahul: That's probably a good candidate -- but how to find it algorithmically? – user2033412 May 29 '18 at 16:25
  • 4
    If you want an exact computation for Rahul's suggestion, you could look around the notion of medial axis. There is a bunch of literature around that, including approximate computations. An alternative to the medial axis would be the straight skeleton. It's not really the point at max distance, but it should still be an okay candidate. EDIT: to clarify, you want to look at vertices of the medial axis/straight skeleton. – N.Bach May 29 '18 at 16:34
  • 5
    I found the previous question: "Visual center” of a concave polygon. The answer notes that the map-making term of art for the point you seek is the region's "pole of inaccessibility". – Blue May 29 '18 at 22:16

0 Answers0