For the center of gravity you could just use the centroid of the mesh.
You can calculate the centroid by averaging the positions of all its
vertices.
As for the volume, you could easily calculate it using monte carlo
integration. Just generate random samples inside a bounding box of known
volume, and test how many of those samples fall inside the object. The
volume then is inside / num_samples * box_volume.
--
John Tsiombikas (Nuclear / Mindlapse)
http://nuclear.sdf-eu.org/
> For the center of gravity you could just use the centroid of the mesh.
> You can calculate the centroid by averaging the positions of all its
> vertices.
Actually, to get an acurate position of the center of gravity, you first
need the volume.
> As for the volume, you could easily calculate it using monte carlo
> integration. Just generate random samples inside a bounding box of known
> volume, and test how many of those samples fall inside the object. The
> volume then is inside / num_samples * box_volume.
And why would you do it with a monte carlo method? Making a MC efficient,
requires to prepare the mesh data with some acceleration structure, some
spatial subdivision scheme. Like BSP or a Kd tree. But if you have the
spatial subdivision, one can directly compute the volume from that.
Wolfgang
This can fail - some parts of the model might have more
detail/vertices than others.
A real center of gravity is quite hard to calculate from
a polygon mesh.
--
<\___/>
/ O O \
\_____/ FTB.
If the mesh is a simple polyhedron, then the computation is fairly easy.
http://www.geometrictools.com/Documentation/PolyhedralMassProperties.pdf
If the mesh is not a simple polyhedron but can be decomposed into
a disjoint union of polyhedra, then you can apply this same result
to each polyhedron and combine.
--
Dave Eberly
http://www.geometrictools.com
There's a script on http://blenderartists.org/forum/showthread.php?p=1262210
which suggests the following:
To find the center of gravity (or "centroid") of a polygonal mesh:
convert all of its faces to triangles, and average the centroids of
all of the triangles, weighted by the doubled area of each face.
Wikipedia calls it <a href="http://en.wikipedia.org/wiki/
Centroid#Centroid_by_geometric_decomposition">Centroid by Geometric
Decomposition</a>.
C = Centroid <vector>, A = (area of a face * 2)
R = face centroid = average of vertices making the face <vector>
C = [sum of all (A*R)] / [sum of all R]
Hey Jef,
There's a typo in the last line of my last post. That should be C =
[sum of all (A*R)] / [sum of all A]
And that's ultimately from http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/
Cheers,
Peter
Good point -- to be clear, the formula I posted applies only to a mesh
as if it was constructed from 2-dimensional sheets of constant
density, and ignores any enclosed volume.
> To find the center of gravity (or "centroid") of a polygonal mesh:
Just to nit pick, the center of gravity (and even center of mass) isn't exactly the same thing as the
centroid, as the centroid is the geometric center while the center of gravity is the point on a solid where
it is possible to apply a single force which is statically equivalent to the effect gravity has on it. It
just happens that under some circumstances the two points coincide.
Rui Maciel
Precisely -- and those points coincide for any 2D shape or 3D mesh
with no thickness -- correct?
My apologies for the ambiguity. Nits are our business, after all.
P
> Precisely -- and those points coincide for any 2D shape or 3D mesh
> with no thickness -- correct?
Not necessarily. They do only if a couple of specific conditions are verified. If the mass isn't distributed
uniformly or if the gravity field is not constant across the domain then the centroid, center of mass and
center of gravity will not coincide.
Rui Maciel