Finding the centre of gravity of a 2D object

Subscribe to Finding the centre of gravity of a 2D object 22 posts

avatar for jasonjie88 jasonjie88 302 posts
Flag Post

Assuming you know the lines that form the outline of an object, how do you determine the center of gravity of an object. I mean, it’s typically easy with a box and circle, where it’s generally the centre of an object, but what about with complex shapes like a hammer or a chair or something?

 
avatar for Mond Mond 749 posts
Flag Post

Take half the dimensions of the bounding box. But that is not the center of gravity…the center of gravity would depend on the mass distribution intrinsic to the object.

 
avatar for Draco18s Draco18s 6860 posts
This post has been removed by an administrator or moderator
 
avatar for Shake_N_Baker Shake_N_Baker 53 posts
Flag Post

Concave shapes can be represented by multiple convex shapes put together. You could find the center of the convex shapes relatively easily using bounding boxes as Mond said. With the centers of the convex shapes you could then get the average of them (you could even add weights to certain convex shapes center of mass) and this should more or less be the center of the complex concave shape. A hammer could be seen as a rectangle handle and a square head put together, both of which have easy to calculate centers of mass. The hammer head could perhaps have twice the weight of the handle so when averaging the center of mass would lean more towards the center of the hammer head than the center of the handle.

 
avatar for Mond Mond 749 posts
Flag Post

Are you going to help him..or just fuss at me?

If the object doesn’t change it’s shape dynamically you could use trial & error to determine the center and just specify it with the object so when you rotate it (as it flys through the air for instance) it would look realistic.

 
avatar for downdown downdown 36 posts
Flag Post

sounds like you need a physics engine, manually doing what your suggesting is a huge under taking

 
avatar for JamesObscura JamesObscura 250 posts
Flag Post

Find the average position of non-transparent pixels. Assuming pixels all have an equal mass.

Come on guys. This isn’t that hard.

 
avatar for Mond Mond 749 posts
Flag Post

It’s not hard if you assume a homogeneous distribution of mass.

 
avatar for Draco18s Draco18s 6860 posts
Flag Post
Originally posted by Mond:

It’s not hard if you assume a homogeneous distribution of mass.

If you assume a spherical cow of uniform density…

 
avatar for Draco18s Draco18s 6860 posts
Flag Post
Originally posted by Shake_N_Baker:

You could find the center of the convex shapes relatively easily using bounding boxes as Mond said.

I am sure that you’ll find that that is not always the case.

Looking at the overall object, the center of mass is not where the gray lines come together (although that is the center of the bounding box1). It is a convex shape, but it’s center of mass is not that easy to determine.

1 or very near, I wasn’t mathematically precise when I drew it.

 
avatar for Shake_N_Baker Shake_N_Baker 53 posts
Flag Post

Woops! You’re right. The center of a right triangle for instance would most definitely not be at the center of its bounding box, so scratch what I said about that. I think you could find the center of a convex shape by averaging the X/Y coordinates of each vertex though. And after that I think the concave shapes should still be the average of the convex centers.

 
avatar for jasonjie88 jasonjie88 302 posts
Flag Post

It seems that Shake_N_Baker got the answer I was looking for. According to a NASA website, anyway. 1 When I looked at the site, I just looked at the bottom, which basically said you had to enter a mass distribution, and then perform three-fold integration. Nightmare, considering I was only using lines. But I’ve found it now, so thanks for the help.

1 A NASA website

 
avatar for ErlendHL ErlendHL 1312 posts
Flag Post

If you were to implement really realistic physics, you can’t just deal with one center.

I’m thinking like this: You have a little circle floating around. And it meets a big long line. Do you want the little object to be dragged towards one point of the line? If you want to implement a point of gravity, it should also be affected by the position of the other object (the little circle).

Maybe I’m wrong, I don’t know.

 
avatar for Ace_Blue Ace_Blue 1082 posts
Flag Post

For a uniform object triangle: average of the vertex positions.

For a non-uniform object: Weighed average of the vertex position, with the weight chosen ‘appropriately’.

 
avatar for JWBSoftware JWBSoftware 106 posts
Flag Post

Average of the vertex positions won’t work. The image above is an example; it has far more vertices on the left side, so an average would be to the left of the actual centre.

I would do it by triangulating the object, if the shape is polygonal. The centre of each of those is 1/3 from each face, and the total COG can be found by doing a weighted average, weighted by each triangle area (as if the shape is uniform the mass and area are proportional).

 
avatar for Draco18s Draco18s 6860 posts
Flag Post

Average of verticies would work, possibly, if and only if, the shape is convex. I suspect it’d be pretty close, anyway.

 
avatar for Ace_Blue Ace_Blue 1082 posts
Flag Post
Originally posted by JWBSoftware:

Average of the vertex positions won’t work. The image above is an example; it has far more vertices on the left side, so an average would be to the left of the actual centre.

That image above also has a lot more of the object on the left side of its middle, so the example is kind of underwhelming, but indeed, the average of vertex positions only works for homogeneous triangles. So the hard part would be decomposing the shapes into homogeneous triangles, if that’s even possible for a given shape. The easy part is to compute the center of gravity and mass (proportional to surface area) of each triangle and do a weighed average of those.

 
avatar for jasonjie88 jasonjie88 302 posts
Flag Post

What about calculating a centre of gravity by weighting the vertices based on their y-values? For example, if one point is higher than another, it weighs more.

 
avatar for Draco18s Draco18s 6860 posts
Flag Post
Originally posted by jasonjie88:

What about calculating a centre of gravity by weighting the vertices based on their y-values? For example, if one point is higher than another, it weighs more.

Look at the object I posted and tell me again if that’ll work.

 
avatar for vesperbot vesperbot 1847 posts
Flag Post

by the way, will an iterative algorithm work? Do a triangle-split with a first approximation of a center (the average of all vertices) to be used as one of the triangle’s vertices, then calculate the average of those triangles’ mass centers as the second approximation, triangles should be weighed by their squares. This shuold converge to the correct mass center (or give it at once).

 
avatar for JWBSoftware JWBSoftware 106 posts
Flag Post
Originally posted by jasonjie88:

What about calculating a centre of gravity by weighting the vertices based on their y-values? For example, if one point is higher than another, it weighs more.

No. One way to think about it is “what if I added a vertex?” E.g. add a vertex between two others. Move it slightly if you want so it’s no longer on a straight line between them, though that’s not needed. Then ask “what difference does that make?”.

If you’re just summing and averaging vertices then adding one more will tip your sum towards that vertex. And as one can be added so can ten or 100 on one side, without changing the shape at all.

If it’s triangles then adding a vertex creates a new triangle, or splits an existing one in two, but they are smaller and add up in size to the large one. So they contribute the same to the COG calculation. In fact adding vertices to create triangles can be part of triangulation to do the calculation.

 
avatar for cashughes cashughes 34 posts
Flag Post

You can find the centroid of a simple polygon with the function they give you. (On the polygon page)

The center of gravity depends on the density of the shape. If it is uniform in density, then the center of mass, or center of gravity, is the centroid. Otherwise, you have to weight the points based on their specific weight.