[vtkusers] compute polygon centroids and normals

David.Pont at ForestResearch.co.nz David.Pont at ForestResearch.co.nz
Sun Jul 21 18:07:28 EDT 2002


Matt wrote:

   I am computing the centroid of each polygon in a
   vtkpolydata (which are triangles) as well as the
   normal of each triangle. I have done this by
   extracting the verticies of each triangle and
   computing the centroid by taking the average of the 3
   verticies. I am fitting a plane to the verticies to
   get the normal of each triangle. I feel like I am
   reinventing the wheel - I have looked but I haven't
   found a vtk function that does this. Any suggestions?

Take a look at vtkCellCenters
http://public.kitware.com/VTK/doc/release/4.0/html/classvtkCellCenters.html

For normals check vtkPolyDataNormals as already suggested. If you really
need to calculate normals on a cell by cell basis you can create an
instance of vtkPolygon, then use the ComputeNormal method, passing it the
points from your cell with something like: cell->GetPoints().


   Also- how can I order verticies in my polydata such
   that they are always referenced clockwise or
   counterclockwise for each triangle? I am thinking this
   may help with providing consistently oriented normals
   (ie: outward or inward). Any suggestions would be
   greatly appreciated!

Try ConsistencyOn with vtkPolyDataNormals which should "... reorder
polygons to insure consistent orientation ..."

regards, Dave Pont




More information about the vtkusers mailing list