Need to find a lua algorithm to find the visual cetner of a polygon for my game
Is there a way to implement this in lua? Mabye a library for this?
Finding the visual center of a polygon
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Finding the visual center of a polygon
Some other languages such as R have libraries supporting this.
AFAIK there is nothing for LOVE / Lua, so in the meantime you can read on how such algorithm works and you can potentially program it yourself:
https://blog.mapbox.com/a-new-algorithm ... 77e6492fbc
Or just port it from JS:
https://github.com/mapbox/polylabel
AFAIK there is nothing for LOVE / Lua, so in the meantime you can read on how such algorithm works and you can potentially program it yourself:
https://blog.mapbox.com/a-new-algorithm ... 77e6492fbc
Or just port it from JS:
https://github.com/mapbox/polylabel
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
Re: Finding the visual center of a polygon
Your image doesn't look like a polygon, but like something painted / raster data.
Is your input shape polygonal, or is it a bitmap, or something else? Is it supposed to be animated? Is the center always in the same position, or do you need to calculate the nearest center towards some arbitrary point?
Without knowing how it's supposed to work, it's difficult to suggest things.
Because it could be something as simple as casting a ray and getting the average between the "enter point" and "exit point":
Is your input shape polygonal, or is it a bitmap, or something else? Is it supposed to be animated? Is the center always in the same position, or do you need to calculate the nearest center towards some arbitrary point?
Without knowing how it's supposed to work, it's difficult to suggest things.
Because it could be something as simple as casting a ray and getting the average between the "enter point" and "exit point":
Re: Finding the visual center of a polygon
There might be algorithms to achieve this kind of thing, but I'm not sure how they could work, since where the centre is can be subjective if you aren't using centre of mass or something similar (e.g. a perfectly round ring would have an infinite numer of places it can be)
I guess the real question is what do you need it for? It's possible that there might be better ways to get what you want.
I guess the real question is what do you need it for? It's possible that there might be better ways to get what you want.
Dragon
Who is online
Users browsing this forum: Ahrefs [Bot], slime and 4 guests