Finding the visual center of a polygon

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
whatevers
Prole
Posts: 1
Joined: Sun Feb 18, 2024 5:54 pm

Finding the visual center of a polygon

Post by whatevers »

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?

Image
User avatar
dusoft
Party member
Posts: 629
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Finding the visual center of a polygon

Post by dusoft »

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
RNavega
Party member
Posts: 353
Joined: Sun Aug 16, 2020 1:28 pm

Re: Finding the visual center of a polygon

Post by RNavega »

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":
temp.jpg
temp.jpg (29.44 KiB) Viewed 832 times
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: Finding the visual center of a polygon

Post by Bobble68 »

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.
Dragon
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], slime and 4 guests