I have N points. Each point has X and Y coordinates.
I need to find X and Y of center of mass this points. Can you give me an algorithm to accomplish this task?
Is there something wrong with just taking the weighted average by mass?
for each point n
{
totalmass += n.mass
totalx += n.x*n.mass
totaly += n.y*n.mass
}
center = (totalx/totalmass,totaly/totalmass)
add additional dimensions as appropriate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With