I've been messing around with some 3D stuff (more specifically with LibGdx, but it doesn't matter for this question) and recently I've found a problem trying to calculate per-face normal for a simple triangle.
The triangle mesh that I've generated has the following vertices (also shown in the link below):
v0 = [3 , 0 , 0] //X, Y, Z
v1 = [1.49 , 0.86 , 0] //X, Y, Z
v2 = [3 , 0 , -1] //X, Y, Z
For calculating the face normal for that triangle mesh I've used a function that I was able to find in many tutorial/examples websites (with minor modifications):
private Vector3 calculateNormal(float vX1, float vY1, float vZ1,
float vX2, float vY2, float vZ2,
float vX3, float vY3, float vZ3) {
Vector3 edge1 = new Vector3(vX1, vY1, vZ1).sub(vX2, vY2, vZ2);
Vector3 edge2 = new Vector3(vX2, vY2, vZ2).sub(vX3, vY3, vZ3);
Vector3 crsProd = edge1.crs(edge2); // Cross product between edge1 and edge2
Vector3 normal = crsProd.nor(); // Normalization of the vector
return normal;
}
After passing the values of the 3 vertices that formed the triangle into this method, I got the following as a result:
[-0.49, -0.86, 0.0]
Representation of the Triangle Mesh and the Normal Vector (Image)
Problem 1:
From what I have read, I don't think that the values of the calculated normal for that triangle are correct. My guess is that the normal should be positioned somewhere where it is perpendicular to the center of the triangle (X should be positive and Z should have a negative value).
Problem 2:
After calculating the per-face normal for the triangle, should all vertices of the triangle have the same per-face normal values, like so:
verticesArr[v0Idx + 0] = 3; //Position
verticesArr[v0Idx + 1] = 0; //Position
verticesArr[v0Idx + 2] = 0; //Position
verticesArr[v0Idx + 3] = -0.49; //NormalX
verticesArr[v0Idx + 4] = -0.86; //NormalY
verticesArr[v0Idx + 5] = 0; //NormalZ
verticesArr[v1Idx + 0] = 1.49; //Position
verticesArr[v1Idx + 1] = 0.86; //Position
verticesArr[v1Idx + 2] = 0; //Position
verticesArr[v1Idx + 3] = -0.49; //NormalX
verticesArr[v1Idx + 4] = -0.86; //NormalY
verticesArr[v1Idx + 5] = 0; //NormalZ
verticesArr[v2Idx + 0] = 3; //Position
verticesArr[v2Idx + 1] = 0; //Position
verticesArr[v2Idx + 2] = -1; //Position
verticesArr[v2Idx + 3] = -0.49; //NormalX
verticesArr[v2Idx + 4] = -0.86; //NormalY
verticesArr[v2Idx + 5] = 0; //NormalZ
I ask this second question because I've seen tutorial and examples where is shown a different perpendicular normal vector for each one of the vertices of a triangle (for calculating per-face normals and not per-vertex normals).
