#### Archived

This topic is now archived and is closed to further replies.

# Calculating Normals

This topic is 5748 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

\ / First of all, I wish everybody a Merry X-mas / \ Ok.. Now back to my problem. How do I calculate Normals?? I''m not sure.

##### Share on other sites
OK, although this is covered *many* times across the internet (try googling):

The normal to a triangle or some other polygon can be calculated by taking the cross product of two adjacent edges.

Say the triangle is represented by three (3D) points Pi.

Edge 1 can be E1 = P2 - P1
Edge 2 can be E2 = P3 - P1

Now normal N is

N = E1 X E2

Where X is the cross product, defined like this in a function:

    inline Vector3 Cross(const Vector3& v1,const Vector3& v2){    double c0 = ( v1.c[1] * v2.c[2] ) - ( v1.c[2] * v2.c[1] );    double c1 = ( v1.c[2] * v2.c[0] ) - ( v1.c[0] * v2.c[2] );    double c2 = ( v1.c[0] * v2.c[1] ) - ( v1.c[1] * v2.c[0] );    return Vector3(c0,c1,c2);}

Now if you want normals for a smooth mesh (ie normal per vertex), you need to accumulate the normals for each triangle for each vertex and then average them together (and renormalize if necessary).

[edited by - JuNC on December 26, 2002 3:14:34 PM]

##### Share on other sites
I would suggest gametutorials.com they have a nice tutorial on normals and all that. This is where i learned. also, i do beleive that NeHe has a tut on them too.

IT Administrator / Software Engineere
http://drdsoftware.cjb.net

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5
frob
13

• 9
• 14
• 10
• 9
• 17
• ### Forum Statistics

• Total Topics
632601
• Total Posts
3007359

×