PDA

View Full Version : Finding the normals of points

outlander78
03-02-2001, 06:31 AM
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!

Andrew

DaViper
03-02-2001, 06:42 AM
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
and
Edge2 = P3 - P2
and then compute the normal using the crossprodukt:
Normal = Edge1 X Edge2
last step is to normalie it
Normal=Normal/|Normal|

hope that helps
Chris

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

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

Tim Stirling
03-02-2001, 08:34 AM
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.

outlander78
03-03-2001, 09:21 AM
Chris, that was exactly what I needed. Thank you very much!

cheers,
Andrew

Tim Stirling
03-03-2001, 11:53 PM
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.

DaViper
03-04-2001, 11:24 PM
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