Center of mass

Started by
7 comments, last by oliii 16 years, 2 months ago
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
Advertisement
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.





Edit: You can use the Lock function of the vertex buffer to retrieve an array containing the vertices in the buffer.
Best regards, Omid
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.
Quote:Original post by Omid Ghavami
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.


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.

--www.physicaluncertainty.com
--linkedin
--irc.freenode.net#gdnet

Quote:Original post by jjd
Quote:Original post by Omid Ghavami
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.


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.
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.

Everything is better with Metal.

You are right of course, I made a silly mistake [ignore]
Shouldn't be posting when I'm in a hurry [embarrass]
Best regards, Omid
Quote:Original post by oliii
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.


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.
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.

Everything is better with Metal.

This topic is closed to new replies.

Advertisement