I have a triangulated polyhedron (not necessarily convex) and the following information:
A list of the position of each vertex. A list of the vertex triples that define each face. A list of the vertex normals (Here the vertex normals are vectors from each vertex that are calculated by averaging face normals (see below) around each vertex).
I would like to calculate the list of face normals (The normalized vectors perpendicular to the plane of each face, pointing outward).
You can simply determines the orientation of crossed normal by dot it with one of vertex normal or average of all 3 vertices.
Here is the pseudo code:
Vec3 CalcNormalOfFace( Vec3 pPositions[3], Vec3 pNormals[3] )
{
Vec3 p0 = pPositions[1] - pPositions[0];
Vec3 p1 = pPositions[2] - pPositions[0];
Vec3 faceNormal = crossProduct( p0, p1 );
Vec3 vertexNormal = pNormals[0]; // or you can average 3 normals.
float dot = dotProduct( faceNormal, vertexNormal );
return ( dot < 0.0f ) ? -faceNormal : faceNormal;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With