Provided the coordinates of the triangle’ three vertex, how to calculate the normal of the three vertex?
typedef struct { float x, y, z; } Vertex;
Vertex v1, v2, v3;
Vertex e1, e2, e3;
//
// INIT v1, v2, v3 HERE...
//
//
// EDGE 1 VECTOR
//
e1.x = v2.x - v1.x;
e1.y = v2.y - v1.y;
e1.z = v2.z - v1.z;
//
// EDGE 2 VECTOR
//
e2.x = v3.x - v1.x;
e2.y = v3.y - v1.y;
e2.z = v3.z - v1.z;
//
// CALCULATE THE NORMAL
//
e3.x = e1.x*e2.z - e1.z*e2.y;
e3.y = e1.y*e2.x - e1.x*e2.z;
e3.z = e1.z*e2.y - e1.y*e2.x;
Don’t forget that e3 will not be unit length, depending on the case you need the extra normalization step.