Center of mass

Can somebody help me how to find the center of mass of n objects?
Not without more information. Your question is incredibly vague.
I have a project in c++ .. The center of mass of n objects. what information do u need ?
does the n object have mass? if so:
1
2
X=x_1*m_1+x_2*m_2+...+x_n*m_n
              n

if not:
1
2
X=x_1+x_2+...+x_n
         n

the same for Y...
Please correct me if I'm wrong (although I don't think so)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
static const int N = 10;
struct Object
{
    double xpos;
    double ypos;
    double mass;
} objects[N];

Object centroid = { 0, 0, 0 };

for (int i = 0; i < N; ++i)
{
    centroid.xpos += objects[i].xpos * objects[i].mass;
    centroid.ypos += objects[i].ypos * objects[i].mass;
    centroid.mass += objects[i].mass;
}

centroid.xpos /= (double)N;
centroid.ypos /= (double)N;
Topic archived. No new replies allowed.