# Surface Normal?

Have I made a boo boo?
Sometimes my triangles are coming out left handed rather than right handed and i’m not sure why… I think it might be this surface normal… but not sure.
Does this look correct?

[code]Public Function ComputeFaceNormal(t as WalkingTetraHedrons.Triangle) as WalkingTetraHedrons.XYZ
//Set Vector U to (Triangle.p2 minus Triangle.p1)
//Set Vector V to (Triangle.p3 minus Triangle.p1)

//Set Normal.x to (multiply U.y by V.z) minus (multiply U.z by V.y)
//Set Normal.y to (multiply U.z by V.x) minus (multiply U.x by V.z)
//Set Normal.z to (multiply U.x by V.y) minus (multiply U.y by V.x)

dim U, V, norm as WalkingTetraHedrons.XYZ
dim len as single

U.x = t.p(1).x - t.p(0).x
U.y = t.p(1).y - t.p(0).y
U.z = t.p(1).z - t.p(0).z

V.x = t.p(2).x - t.p(0).x
V.y = t.p(2).y - t.p(0).y
V.z = t.p(2).z - t.p(0).z

norm.x = U.y * V.z - U.z * V.y
norm.y = U.z * V.x - U.x * V.z
norm.z = U.x * V.y - U.y * V.x

len= sqrt((norm.xnorm.x) + (norm.ynorm.y) + (norm.z*norm.Z))

norm.x = norm.x / len
norm.y = norm.y / len
norm.z = norm.z / len

return norm

End Function
[/code]

Yes. To know the orientation of a triangle you need the normal.
Cross product of sides vectors (as you have done) is the easiest way.
After RealBasic eliminated Vector3D classes, I had to create my own Vector3D class to get all this work done in a more readable way.
However, once you have the normal, if your scene can move, you need to find also the normal to screen, because you must know if you are seeing the front side or the back side of the triangle.
So, you will have to use the dot product of these two normals to get the side you are seeing at this moment.