Finding the normals of points

Could some please provide some sample code for finding the normals of vertices (as opposed to surfaces)? I generally use triangles, but code for quads would be appreciated too!

thanks for your time, guys,

If P1 is your first point, P2 your second, and P3 your third, and if they are counter-clockwise, treating them as vectors you can write:
Edge1 = P1 - P2
Edge2 = P3 - P2
and then compute the normal using the crossprodukt:
Normal = Edge1 X Edge2
last step is to normalie it

hope that helps

[This message has been edited by DaViper (edited 03-02-2001).]

[This message has been edited by DaViper (edited 03-02-2001).]

To calculate vertex normals simply take the average of all the face normals that are connected by that vertex. The only dificulty is finding which faces are connected, this depends on your data and structure.

Chris, that was exactly what I needed. Thank you very much!


Chris’s method would only give you the face normal, if this is what you want then fine but i think you wanted vertex normals in which case you will also have to do what I said and calculate the average normal of the faces attached to that vertex.

Andrew, Tim is right my calculations only give you the face normals, if you want the average of all normals you have to do what Tim said