#Not sure why the vertical one are not
1 messages · Page 1 of 1 (latest)
Let's say you have label: "Area size: 400m^2" - it's width is greater than height always so that's why the vertical bars would not fit the label
Not following you. The width and the height are the same
Oh, sorry! the width and height of the LABEL itself
Oh, you are trying to place a label inside a shape.
Like the whole phrase is always longer than taller.. if I'm clear 😆
Yeah, exactly!
So at the end, we are not placing a point, but a box.
The problem is:
What is the place where the margin of the box would be the largest.
It's true, but I think if we have a center point then in most cases there would be no problem with the rect box to overlap outside
Hmm.. I think it's not true, I'll show you why
So, we could work the following:
What is the point with largest horizontal space.
In that shape the red box is larger, but the best place to put the label is the green one:
Why is it the case ? We need to define the problem without ambiguity before solving it.
Okay, you are indeed right...
I found the js library that seems to resolve this problem but I don't know if I can even replicate such algorithm:
https://github.com/mapbox/polylabel
It's weird how little is there about this topic
Do you see how the described the problem. "the most distant internal point from the polygon outline"
Here is the ss of some game having the labels inside some shapes as well
I've read about it on some blog and I think it meets the idea of putting the label inside the best spot:
The example of the right wouldnt be the best spot ?
Yeah, certainly
It's visually the center of this concave shape. I know the center of the mass is outside it
But the green point is the most logical place to place a label in my opinion
I mean, the real one would be in the center of the lower part of the rectangle
Same for the left example ofc
I would be happy with any solution that at least fit within this rule that the label has to be inside the shape. The best solution would be to center it but it's not required that much now
Could you state your problem without ambiguity ?
My problem is that I can make a label that is centered inside the CONVEX polygon. But I can't if it's a NON-CONVEX (concave)
That's the main problem for me
You need to define the second half of the problem. I proposed multiple definition, be there were not what you wanted.
We cannot work on solving something that has not been defined.
Okay let me draw some examples so we are on the same page then
I need a word base definition like: "the most distant internal point from the polygon outline"
Otherwise, the problem is: What is the problem without ambiguity.
But I can't find the better wording than:
"The center point of an concave shape that lays in that shape"
Don't mind with the box etc. as we said earlier, just as the above ^
The issue is that the center point of a concave shape does not exists.
So, define the center point of a concave shape.
If you cannot define that, you wont be able to solve your issue.
Looking at this map of US all the labels are well centerized inside each state
For example the Texas is the state with an concave shape
I'm just hopeless now xD I know it's hard to define this problem as I spent whole day on it..
I don't know what is the best way to call it but I would like to not pay attention to details like the case of Missisipi
Maybe the best way to resolve is to find the biggest possible rectangle in given shape and take it center as a center point of that shape and put label in it?
Look at Lousiana then. It looks like the L shape one where you said the corner was the best spot
What do you think..
Yeah in that case you are right, and it should be on the 'bottom' of an L as it is on the map
I don't think so.. Not without struggling for sure
I would start by trying to search on internet. Ask Chatgpt, that could be a good use case for that AI.
Is it even possible to find the largest rectangle in given non-convex shape?
Good point..
What you want to know is what is the algorithmic complexity
but in your case, I'm pretty sure it does not even matter.
If it were something like a map with a lot of irregularity.
it would be something else
Yeah, thanks.. I tried before for the previous things but it's a little limited and with any concave shape it seems to have a huge problem
No there are sets of 3 to like 20 points maximum.. so the level of complexity is practically a zero
Thanks for help, will inform you tomorrow if I found the solution
See how it could help you.
Beware though, it is really goods at giving answer that seem to work but does not.
In that shape the future algorithm would take the '2' as the best place to place a label, but logically it should be the '1'.
oh..
Never mind
The biggest box, not the widest one.. My bad
But let's say the '2' is a lot wider so the area of it is greater than the area of '1'
So there is a possibility to get weird result
But at least it resolves the problem of the label being inside this shape
Which is already huge
I feel like that you cold solve the problem like a CSP. Your graph would be all the possible configuration of line such as D is to the left of B, A is to the top of C and that the resulting rectangle is fully inside the polygone.
The graph being the starts that is not a valid state.
You can then use any pathfinding algorithm you want.