Hey guys, this is my first post on the forums I usually just lurk around heh. Anyway this is an awesome group of people from what I can tell and I intend to make a lot more use of Gideros very soon with some Android apps. Since so many awesome people are sharing their code and libraries I wanted to do the same for you guys.
I hope someone finds this useful for something I haven't thought of yet.
One of my apps needed to place labels on the polygon's it is using so I wrote some functions to find the center--centroid --of any polygon they are given based on math formulas. I am guessing some of you guys could make some use of these types of functions, so here they are.
To make it work you will need to have your polygon points in a table with x, y values as pairs like the example below, or you can modify the functions to fit your data needs:
local poly = {
{x=0, y=100},
{x=100, y=50},
{x=100, y=100}
}
-- Find the center points for this polygon.
local cent = findCentroid(poly)
-- Output the centroid points in case someone wants to check them. <img class="emoji" src="https://forum.giderosmobile.com/resources/emoji/smile.png" title=":)" alt=":)" height="20" />
print("Center X: "..cent.x, "Center Y: "..cent.y) |
A much larger example is provided in the attached code as well. Enjoy
Comments
Welcome to the forum :-h
cheers
evs
P.S. (The forums are really awesome as well I love the fact I am hearing posts from the devs all the time and answers to questions, it's a great feeling for the SDK)
Likes: gorkem
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
welcome here !
and thanks for sharing these useful functions!
ciao ciao
Gianluca.
www.tntengine.com
Likes: gorkem