What is the fastest way to find the "visual" center of an irregularly shaped polygon?
I have found a very good solution to this from MapBox called Polylabel. The full source is available on their Github too.
Essentially it tries to find the visual centre of the polygon as T Austin said.
Certain details suggest this may be a practical solution:
Unfortunately, calculating [the ideal solution ] is both complex and slow. The published solutions to the problem require either Constrained Delaunay Triangulation or computing a straight skeleton as preprocessing steps — both of which are slow and error-prone.
For our use case, we don’t need an exact solution — we’re willing to trade some precision to get more speed. When we’re placing a label on a map, it’s more important for it to be computed in milliseconds than to be mathematically perfect.
A quick note about usage though. The source code works great for Javascript out of the box however if you intend on using this with a "normal" polygon then you should wrap it in an empty array as the functions here take GeoJSONPolygons rather than normal polygons i.e.
var myPolygon = [[x1, y1], [x2, y2], [x3, y3]];
var center = polylabel([myPolygon]);
If you can convert the polygon into a binary image, then you can use the foundation that exists in the field of image processing, e.g.: A Fast Skeleton Algorithm on Block Represented Binary Images.
But this is not really reasonable in the general case, because of discretization errors and extra work.
However, maybe you find these useful:
- Straight skeleton of a simple polygon
- Determining the Skeleton of a Simple Polygon in (Almost) Linear Time
EDIT: Maybe you want to look for the point that is the center of the largest circle contained in the polygon. It is not necessarily always in the observed centre, but most of the time would probably give the expected result, and only in slightly pathological cases something that is totally off.
How about:
If the centroid of the polygon is inside the polygon then use it, else:
1) Extend a line from the centroid through the polygon dividing the polygon into two halves of equal area
2) The "visual center" is the point half way between the nearest point where the line touches the perimeter and the next point cutting the perimeter in the direction going away from the centroid
Here are a couple of pictures to illustrate it: