[Math] How to find the center of mass of a complex 2d shape

algorithmsgeometry

So I'm hoping someone could help me get a solid algorithm for finding the center of mass of 2D shape without density, based of a set of vertices.

Please explain in simple terms that a non-mathematician could understand (I have no clue how the wikipedia equation works) and easily translate into C++ code for my program! =)

Note: if it makes the algorithm any faster, the complex shapes in my program are really just a group of convex polygons which I can access.

Best Answer

  1. Divide your complex polygon into non-overlapping triangles.
  2. The center of mass for each triangle is the simple average of the coordinates of its three corners. (Because this works for an equilateral triangle, and affine transformations preserve centroids and can take any triangle to any other triangle).
  3. Average the centers-of-mass of all the triangles, weighting by the area of each triangle (which you can find as the 2D cross product of two of its sides).
Related Question