Polygon centroids are often not inside the polygon. Which is not very convenient, e.g. when you want to find a place to slap some text labels on the polygon, or otherwise draw something at where subjectively feels like the "center".
This interactive demo presents a couple solutions that're simple, fast, and sensible.
⬤ gray dot is the canonical centroid.
When the centroid is outside the polygon:
⬤ red dot is obtained by casting a ray from the centroid to the closest edge, and finding the midpoint of the first two intersections between the ray and the polygon. Though it's straightforward, and that the new centroid is quite near the true centroid, sometimes it (arguably) doesn't pick the best spot: it might end up at a "tip" of the polygon that happens to be close to the centroid, which doesn't feel a lot like the "center" (click here for an example).
⬤ green dot is obtained by casting a ray from the centroid that cuts the polygon into two parts equal in area, and taking the midpoint of the first two intersections. (For simplicity and efficiency the area "cut" also considers the first two intersections only).
Sometimes you don't care too much about finding some sort of "center": you just want some big empty space to put text/graphics. Therefore, a third heuristic is introduced:
⬤ orange dot is obtained by looking at all the midpoints of pairs of intersections between the polygon and rays casted from the centroid, and finding the one who is the center of the largest "inscribable" circle among them. It's not necessary to use rays from the centroid to search for the inscribable circle; Indeed, you might find better candidates without this restriction (perhaps with a monte carlo algorithm). But the rays/midpoints of intersections give a quick heurstic of where reasonably good ones might be found.
Finally, even when the centroid is inside the polygon, it might not be at an ideal position, i.e. being too close to an edge, therefore:
⬤ blue dot is obtained by casting one ray from the centroid to the closest edge, and another ray in the opposite direction, and finding the midpoint of the two intersections from each ray. (The blue dot only appears when the centroid is already inside polygon; Likewise, the other three colored dots only appear when it's not.)
Then maybe take the average of all three (i.e. average the direction of the rays, and make a new intersection-midpoint)? Or maybe take the median of the three? Or maybe the average of the average and the median of the three? Or weighted average of the weighted average and the meidan?
Lingdong Huang 2020, supported by the STUDIO for Creative Inquiry.