Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting vertex normals to face normals

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).

like image 782
user1873329 Avatar asked Dec 03 '12 18:12

user1873329


1 Answers

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;
}
like image 50
SeaStar Avatar answered Sep 25 '22 14:09

SeaStar