Polygon label in the real center

Hello everyone!
Does Babylon have something like finding the real center for labels in irregular polygons? I made this playground: https://playground.babylonjs.com/#QNJLCY#28 and when you make eq.
this one is ok:

but not this:
image image


1 Like

The center of a convex polygon can be defined as the average position of all the vertices that compose the polygon.
This should fix your the issue for your first image.
But for concave polygon, it seems like a pretty more difficult topic: Pole of inaccessibility - Wikipedia
So, for a configuration like your second image, the text would be closer to point 4 but not sur it will be in the polygon.

1 Like

I think that linkWithMesh method already takes average positions of all the vertices

Not quite. It takes the center of the projected bounding box.

For 3 points you can use normalized center (bb world center)
For 4 or more, it’s complex, you could try finding the two closest points and then get the center of those, that would work with the shape in your picture and simular shapes, but this will still not support all imaginable shapes.