# Center of mass

This topic is 3891 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi, i want to determine the center of mass of the object with two details of 3D object below: IDirect3DVertexBuffer9 and IDirect3DIndexBuffer9 i think they help to determine the triangles of the object. Thanks

##### Share on other sites
If the mass of your object is uniformly distributed all you need to do is to take the average of the spatial location of the vertices. That is to sum the position of all vertices of your mesh and scale by the reciprocal of the number of vertices.

$\frac{\mathbf \vec v_1 + \mathbf \vec v_2 + ... + \mathbf \vec v_n}{n}$

Edit: You can use the Lock function of the vertex buffer to retrieve an array containing the vertices in the buffer.

##### Share on other sites
Omid, does that actually work. That was the initial answer i came up with, but then i thought otherwises. Take for example an object that is something like a cube with a really small high poly sphere attached to it. The sphere would have alot of triangles and the cube would not, this doesn't mean that the sphere has more mass.

Correct me where i'm wrong.

##### Share on other sites
Quote:
 Original post by Omid GhavamiIf the mass of your object is uniformly distributed all you need to do is to take the average of the spatial location of the vertices.

Mo, this is wrong. If you have a detailed region in the mesh with a high concentration of vertices, your suggestion will skew the "center of mass" towards the higher concentration of vertices. Another way of putting this is that if you subdivided a face of the mesh, i.e. effectively adding more vertices, your center of mass would change, and move towards the greater concentration of vertices, even thought the volume of the mesh would be unchanged.

##### Share on other sites
Quote:
Original post by jjd
Quote:
 Original post by Omid GhavamiIf the mass of your object is uniformly distributed all you need to do is to take the average of the spatial location of the vertices.

Mo, this is wrong. If you have a detailed region in the mesh with a high concentration of vertices, your suggestion will skew the "center of mass" towards the higher concentration of vertices. Another way of putting this is that if you subdivided a face of the mesh, i.e. effectively adding more vertices, your center of mass would change, and move towards the greater concentration of vertices, even thought the volume of the mesh would be unchanged.

Thats what i thought.

##### Share on other sites
if the object is closed then you can use a uniform grid of points, see which of these points are inside the object, and use the standard integration method to compute the centre of mass, inertia, and even the mass itself.

##### Share on other sites
You are right of course, I made a silly mistake [ignore]
Shouldn't be posting when I'm in a hurry [embarrass]

##### Share on other sites
Quote:
 Original post by oliiiif the object is closed then you can use a uniform grid of points, see which of these points are inside the object, and use the standard integration method to compute the centre of mass, inertia, and even the mass itself.

I've been doing this at work actually. I used a BSP tree to check if each point is inside the mesh, and it works pretty well and didn't take too long to throw together, but you have to be careful that your loaded mesh is closed and that your normals face the right way etc. I had quite a headache over why it didn't work until I realized my models were all messed up. I'm still wondering if there is a faster or more accurate way to accomplish this though.

What are you using the center of mass for? If it's not for physics specifically you may be able to get away with taking the middle of the axis aligned bounding box.

##### Share on other sites
Yeah, T junctions and holes will mess up BSP tree generation.

Another method is to cast a bunch of semi-infinite rays from each point, and count the intersections with the mesh triangles. If the cound is odd, you are outside. if it is even, you are inside.

There are problems with floating point accuracy though, when the ray goes thorugh a vertex or an edge. Either have a algorithm for contact point reduction, or cast several random rays per point (you may get a different count for each), and take which one is the most likely.

say, cast 10 random rays from one point. you have 8 with odd counts, and 2 with even counts. Then the overwhelming number of odd counts mean that the origin of the ray is inside. If there is a close match, try again with different rays or assume the point is on the boundary of the mesh (very close to a triangle so some counts are slightly messed up). It's also easy to see when the smallest intersection value is close to 0.

So, if the mesh has holes in it, the algo will fail, but should still return decent mass properties on average.

1. 1
2. 2
3. 3
4. 4
5. 5

• 14
• 9
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
632911
• Total Posts
3009186
• ### Who's Online (See full list)

There are no registered users currently online

×