Qualcuno sa come trovare le coordinate per il baricentro di un corpo regolare e non?
Anche solo idee
Grazie in anticipo

I don’t have a programming answer right away, but in the real world, the common way to find the center of gravity of an irregular object is to suspend it from an edge of the object and allow gravity to work on the object until the object is still but still suspended.

Then, you draw a line through the object’s center.

You repeat this using a different part of the object to suspend it from.

The two lines you draw should intersect at one point and this is the center of gravity for that object, no matter how irregular.

In programming terms, I’d say that if it’s a two dimensional object, you can pretty much do the same by making a line through it and figuring out where to draw the line so that it splits the object in half and then repeating at a different point of the object.

As for figuring out the angle of such a line - as to how much of an object lies on one side of the line or the other - you could project the object to a pixel render and count the number of pixels on each side.

If you’re in three dimensions, you’d do the same but first project two separate views of the object to 2D.

Now, this is pretty complex and ideally you’d want to do all this before hand and then hard code the result in to your game object rather than having it happen at load time.

If you must have it happen at load time (“but Draco, I make objects on the fly!!”) then you can brute force as above, but know it will be computationally expensive.

If instead, you are willing to “fudge” it - just decide where the center is based upon a best guess and just use it. Most games would do just this because you’re not out to build The Matrix - you are just out to entertain.