I did it, thanks. Find the minimum and maximum x and y. Then, add them up and divide, and this will be the coordinates of the center of the polygon.
local new_x = (max_x+min_x)*0.5
local new_y = (max_y+min_y)*0.5
I did it, thanks. Find the minimum and maximum x and y. Then, add them up and divide, and this will be the coordinates of the center of the polygon.
local new_x = (max_x+min_x)*0.5
local new_y = (max_y+min_y)*0.5
Hi @GamingStudio17,
You may want to investigate the math in the link below… I don’t think that your formula will find the actual center of irregular polygons. Inspecting the irregular triangle that I pasted, your math would find the center of the “bounding rectangle” but not the actual center of the triangle. Anyway, check this post out:
http://stackoverflow.com/questions/5271583/center-of-gravity-of-a-polygon
Best regards,
Brent
I Already Did, thank you. Everything works fine.
Another question, how to make sure that when a message is displayed
WARNING: Polygon could not be generated. The polygon outline is invalid, possibly due to holes or self-intersection.
Then Polygon is removed.
Hi @GamingStudio17,
I don’t have any specific advice on this, unfortunately. Corona will not create an invalid polygon (hence the warning message when you try to), but there’s no way to “pre-detect” that using the warning message. You may refer back to the module I linked you to, which (I think) figures out if a shape is “valid” or not, correct? If it doesn’t, you’ll need to locate some algorithm to step through your vertices and ensure that the shape is valid in two ways: 1) that it’s just one valid polygon (doesn’t result in self-intersection), and 2) the vertices yield only convex bends for proper physical behavior in Box2D.
Best regards,
Brent
Would be great if we can manually switch off the polygon auto-centering, it’s a huge pain and kind of defeats the point of setting vertices when they all get auto-shifted by the auto-centering. Having to calculate the center of the polygon then shift it back to where you originally want it is ridiculous. For example I’m calculating the vertices of a wall then using those to draw a shadow using a polygon. However, since the polygon auto-centers itself the shadow never ends up where it’s supposed to as it ends up auto-centering itself to the wall and not remaining where it’s supposed to be. Perhaps i missed something but it’s really strange and not practical to have polygons auto-center themselves.
I already wrote a polygon can be easily aligned. But thanks to the auto centering, cent polygon always correct.
@ gamingstudio17, hi, Not sure what you’re on about, I was referring to the general issue of polygons auto-centering.
Anyways, @brent, if corona can simply give us the option to switch off auto-centering. I don’t actually even see the point of polygons auto-centering in the first place.
Would be great if we can manually switch off the polygon auto-centering, it’s a huge pain and kind of defeats the point of setting vertices when they all get auto-shifted by the auto-centering. Having to calculate the center of the polygon then shift it back to where you originally want it is ridiculous. For example I’m calculating the vertices of a wall then using those to draw a shadow using a polygon. However, since the polygon auto-centers itself the shadow never ends up where it’s supposed to as it ends up auto-centering itself to the wall and not remaining where it’s supposed to be. Perhaps i missed something but it’s really strange and not practical to have polygons auto-center themselves.
I already wrote a polygon can be easily aligned. But thanks to the auto centering, cent polygon always correct.
@ gamingstudio17, hi, Not sure what you’re on about, I was referring to the general issue of polygons auto-centering.
Anyways, @brent, if corona can simply give us the option to switch off auto-centering. I don’t actually even see the point of polygons auto-centering in the first place.