# How to label a 2d shape in its center (visually what appears to be the center inside the shape)?

i have diffrent shapes that i want to label. but i want the text to be inside the shape.

1) method that i used
so my first thought was to use the area component but in many cases the centroid came outside the shape itself. hence that doesnt work. below you can see there are many points that are outside the shape.

2) 2nd method best result but very slow (need something faster)
second method.gh (15.3 KB)
my next attempt was to populate the shape with points. this made everything run really slow cause i have around 1000s of shapes (but it had the best result)

and then select the points that is farthest away from the edges of the shape.

3) 3rd method (just a little bit faster than the earlier method)
i first used dispatch to seperate the shapes that had holes in them. then i seperated the cnvex and the concave shapes.
for the concave shape i used the area component to find the center for the lable
for the convex shapes and the shapes that had holes in them i used the face boundary component to divide it into faces them found the centers of those faces and then found the center that was furthest away from the edges of the shape.

centers.gh (22.3 KB)

is there a method that is better than this or atleast faster that this.
after finding the center i will use the 3d text tag component to label them

There are some great solutions from @laurent_delrieu on this thread Old Town Roofs

You might generate roofs by his scripts, explode them, extract Midpoint of highest edge and project it to XY plane.
In that manner you can somehow get closer to desired “centrish” position.

1 Like

hey , try this

6 Likes

thats quite a nice solution.(jakinta)
the highest point found with this method should technically be the most centrish point inside the shape.

so while the other methods might fail in some cases to find the centermost point, this method should work in every case.
but the problem with this method is that it take quite a lot of time.

how did you get the name of the component above the component

is it the component on the left side (the one with the glasses on it)
what the name of the component ???

as for the solution i found that even after i find the centerish point on the shape there are some cases in which the text still goes out of the shape, because the text is simply large than the shape. or in some cases when the text is not oriented in the corrent way.

i think i will have to make a rectangle the size of the text and then move the recatngle on the centers of the mesh faces , and check if the rectangle is inside the shape. if the rectangle is outside the shape then i will have to rotate it or change its size.

but that will also take quite a lot of time to compute. so i think i will stick the mesh center method and make do with some text going out of the shape. (of maybe for places where the text is going out simply give it a symbol and mention the name in a legend or something)

…and you might want text to be paralel to closest edge of shape - pick the closest one to accepted point, orient text box…

Let s say if you choose Mid-Text justification it might give you the least number of not-desired outcomes.

yes that should reduce the number of not-desidred outcomes. and improve the speed i will try that thanks

I had the same problem for labeling my pieces, I used the logic with populate (a Monté Carlo one).
The difference is that I also output a point and a direction (a plane) to be able to put my text.

placement text on shapes.gh (13.9 KB)

1 Like