views:

89

answers:

3

Hi,

I know how to find the centroid (center of mass) of a regular polygon. This assumes that every part of the polygon weighs the same. But how do I calculate the centroid of a weightless polygon (made from aerogel perhaps :), where each vertex has a weight?

Simplified illustration of what I mean using straight line:

5kg-----------------5kg
           ^center of gravity

10kg---------------5kg
        ^center of gravity offset du to weight of vertices

Of course, I know how to calculate the center of gravity on a straight line with weighted vertices, but how do I do it on a polygon with weighted vertices?

Thanks for your time!

+3  A: 

You want take a weighted average over all the vertices. So say your vertices are v1, v2, v3 .... vn with masses m1, m2 ...mn and have x and y coordinates v1x, v1y, v2x, v2y etc then to get the center of mass (cx, cy) you want:

cx = (v1x*m1 + v2x*m2 + ... vnx*mn) / (m1 + m2 .... mn) 
cy = (v1y*m1 + v2y*m2 + ... vny*mn) / (m1 + m2 .... mn)

It's essentially the same principle as when you do it for a line.

pheelicks
Great, thank you!
Calle Kabo
In fact, you can call this the definition of centroid :)
Moron
A: 

The formular would be:

Mc = ( sum_from_0_to_max(vertices)( m_i * P_i ) / M )

where Mc is the center of the masses, m_i is the mass of vertex i, P_i the position and M the overall mass.

Try to google for "rigid bodies", I guess you will find a lot helpfull information.

Edit:

In code it would be somethin like this:

Vector3D result; // initialized with 0, 0, 0
Vector3D temp; // sum
long sumMasses = 0;
for( Vertex v : vertices ) {
temp += (v.mass * v.position);
sumMasses+=v.mass;
}
result = temp / sumMasses;

InsertNickHere
+3  A: 

1) Generate a vector for each vertex

2) Multiply each vector for the weight of the vertex

3) Sum the vectors

4) Divide for total mass

5) There's your center of mass!

nico
OMG . . . . . . .
Camilo Martin
@Camilo Martin Why? What's the problem with it?
nico
No problem. I think he just likes the simplicity of it :)
pheelicks
Yes, I was writing a long answer and you came up with this awsome amazing short and elegant answer. :)
Camilo Martin
@CamiloMartin I'm sorry, sometimes it's difficult to understand the tone of a sentence read on Internet. Thank you for the appreciation. :)
nico