How to calculate normal?

Started by
3 comments, last by Alberth 4 years, 7 months ago

Hi,

Can somebody explain to me normals? Am I correct to say a normal points in one direction? How to find that direction? If I draw a triangle, how is the normal calculated and drawn? Or maybe some good links that describe it?

Thanks,

Advertisement
Quote

Am I correct to say a normal points in one direction?

Vectors in general point in one direction, as it were, so that description doesn't really distinguish normals from other vectors. Generally speaking though normals come in pairs, pointing in opposite directions - maybe that's what you mean.

Quote

Or maybe some good links that describe it?

The Wikipedia article:

https://en.wikipedia.org/wiki/Normal_(geometry)

Seems to cover the basics. (I'm not saying the article contains no errors - just that it seems to provide basic coverage.) I imagine searching for something like 'surface normal' might direct you to other useful references as well.

If after that you still have questions, I imagine someone here can provide answers or direct you to further resources.

4 hours ago, SR D said:

If I draw a triangle, how is the normal calculated and drawn?

for a triangle the normal is calculated with cross product using 2 edge vectors:

vec normal = normalize(cross(p2-p0, p1-p0)) // pX being the 3 triangle vertex positions

Cross product gives a vector that is normal two the 2 input vectors, so it does not matter which 2 of the 3 edge vectors you choose. But the normal will either point inwards or outwards. Most people use outwards convention.

The magnitude of the cross product is twice the area of the triangle, so normalize to get unit length.

 

For a vertex you can sum up and normalize all adjacent triangle normals. But it is better to weight the triangle normals with the absolute angle between its two adjacent edges at the vertex.

 

You can visualize the normal to check for correctness, but usually you do not draw it in a game. Instead it is used for lighting or physics calculations.

 

There are lots of tutorials that cover common math problems in programming context (which obviously includes 3D math). You may want to study them for some time to get a better understanding of how vectors etc work.

This topic is closed to new replies.

Advertisement