[vtkusers] Center of Mass Calculation

Dženan Zukić dzenanz at gmail.com
Mon Jun 6 03:48:22 EDT 2011


Hi,

I have some code for calculating center of mass. It is for some QuadEdge
class, and it is meant for for star-shaped objects. Deviation from
star-shape will lead to imprecision.

double calcNewCenter(Cell *qe, vec3& center) //returns volume, center -
center from previous iteration
{
double vol=0, tv;
vec3 newC(0,0,0), tc, a,b,c;
CellFaceIterator cfi(qe);
 Face *f;
while ( (f=cfi.next()) != 0 )
{
 FaceEdgeIterator fei(f);
Edge *e=fei.next();
a=e->Org()->pos;
 e=fei.next();
b=e->Org()->pos;
e=fei.next();
 c=e->Org()->pos;
tv=(a-center) * ((b-center)^(c-center)) / 6.0; //a,b,c - triangle vertices
 //volume of tetrahedron consisting of this face and the old center
tc=(a+b+c+center)/4.0; //center of mass of this tetrahedron
 newC+=(tc*tv);
vol+=tv;
}
 center=newC/vol;
return vol;
}

HTH,
Dženan

On Sun, Jun 5, 2011 at 18:32, soheil ghafurian <soheilghafurian at yahoo.com>wrote:

> Hi
>
> I want to calculate the center of mass of a closed triangular surface. Is
> there a class for doing this? If not should I change the surface into a
> volume and compute the center of the voxels? Is there a class that changes a
> surface into a volume?
>
> I would appreciate your help
>
> Thanks :)
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110606/62d519af/attachment.htm>


More information about the vtkusers mailing list