<font size="2"><font face="verdana,sans-serif">Hi,</font></font><div><font size="2"><font face="verdana,sans-serif"><br></font></font></div><div><font size="2"><font face="verdana,sans-serif">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.</font></font></div>

<div><font size="2"><font face="verdana,sans-serif"><br></font></font></div><div><font size="2" face="&#39;courier new&#39;, monospace"><div>double calcNewCenter(Cell *qe, vec3&amp; center) //returns volume, center - center from previous iteration</div>

<div>{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>double vol=0, tv;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vec3 newC(0,0,0), tc, a,b,c;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>CellFaceIterator cfi(qe);</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>Face *f;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>while ( (f=cfi.next()) != 0 )</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>FaceEdgeIterator fei(f);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>Edge *e=fei.next();</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>a=e-&gt;Org()-&gt;pos;</div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>e=fei.next();</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>b=e-&gt;Org()-&gt;pos;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>e=fei.next();</div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>c=e-&gt;Org()-&gt;pos;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>tv=(a-center) * ((b-center)^(c-center)) / 6.0; //a,b,c - triangle vertices</div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>//volume of tetrahedron consisting of this face and the old center</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>tc=(a+b+c+center)/4.0; //center of mass of this tetrahedron</div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>newC+=(tc*tv);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>vol+=tv;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>center=newC/vol;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>return vol;</div><div>}</div></font></div><div><font size="2"><font face="verdana,sans-serif"><br>

</font></font></div><div><font size="2"><font face="verdana,sans-serif">HTH,</font></font></div><div><font size="2"><font face="verdana,sans-serif">Dženan<br></font></font><br><div class="gmail_quote">On Sun, Jun 5, 2011 at 18:32, soheil ghafurian <span dir="ltr">&lt;<a href="mailto:soheilghafurian@yahoo.com">soheilghafurian@yahoo.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div style="color:#000;background-color:#fff;font-family:times new roman, new york, times, serif;font-size:12pt">

<div>Hi</div>
<div> </div>
<div>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?</div>


<div> </div>
<div>I would appreciate your help</div>
<div> </div>
<div>Thanks :)<var></var></div></div></div><br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br></div>