Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the center of mass of points [closed]

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?

like image 401
Nik Avatar asked Nov 30 '22 05:11

Nik


1 Answers

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.

like image 112
Sconibulus Avatar answered Dec 04 '22 07:12

Sconibulus