找到点质量中心质量、中心

2023-09-11 02:19:30 作者:另类色彩 colouro

我有N个点。每个点具有X和Y坐标。

I have N points. Each point has X and Y coordinates.

我需要找到这个点的质心的X和Y。你能给我一个算法来完成这个任务?

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.