vtkPolygon::ComputeNormal returns wrong directed normal if polygon has more concave than convex vertices
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
Hello,
the methods in vtkPolygon that are purposed for computing the normal of a polygon does not work, if the polygon has more concave than convex vertices. The normal there is an average from all cross-products, that cause a wrong sign of the normal. In Graphics Gems III there is an interesting method from Nevell, that should replace the actual versions of ComputeNormal. A lite version, without optimation for triangles, I provide below:
void ComputeNormal(vtkPoints *pts, vtkIdList *poly, double *n) { n[0] = 0; n[1] = 0; n[2] = 0; double pt0[3], pt1[3];
pts->GetPoint(poly->GetId(0), pt0);
unsigned int nbr = poly->GetNumberOfIds();
for(unsigned int i = 0; i < nbr; i++) { pts->GetPoint(poly->GetId((i+1)%nbr), pt1);
n[0] += (pt0[1]-pt1[1])*(pt0[2]+pt1[2]);
n[1] += (pt0[2]-pt1[2])*(pt0[0]+pt1[0]);
n[2] += (pt0[0]-pt1[0])*(pt0[1]+pt1[1]);
pt0[0] = pt1[0];
pt0[1] = pt1[1];
pt0[2] = pt1[2];
}
vtkMath::Normalize(n); }