Calculating normals for a polygon mesh (3D computer graphics)

4.5k Views Asked by At

I want to write a program to generate arches, a common architectural form, and export them to a wavefront object format for sharing with various three dimensional graphics editors. To do this, I need to generate normals for inclusion in the wavefront object. I understand that normals represent the orientation of a surface at a vertex. I need to understand how to calculate them, and specifically what the i,j,k coordinates signify.

2

There are 2 best solutions below

8
On

If you're creating a polygon mesh, presumably you'll want normal vector given a particular triangular face.

First of all, definitions: a normal on some point of a surface is a vector that points perpendicular to that surface at that point. Since each surface (locally) has two sides, you have two valid directions of normal-vectors: one side on which the vector would point towards the surface, and one side on which the vector would point away from the surface.

Now, suppose you have a triangle determined by the three points $a = (a_1,a_2,a_3), b = (b_1,b_2,b_3),$ and $c = (c_1,c_2,c_3)$. Define $$ v_{ab}=(b_1-a_1,b_2-a_2,b_3-a_3)\\ v_{bc}=(c_1-b_1,c_2-b_2,c_3-b_3) $$ In order to find a normal vector, calculate $v_{ab}\times v_{bc}$ or, for the opposite orientation, $v_{bc} \times v_{ab}$, where "$\times$" here denotes the cross-product.

0
On

Accumulating the Cross-product of component triangles is one way. Glassner notes that the cross of the diagonals of a quad gives the same answer. Coons pointed out that the vector of the areas of the polygons projected onto the coordinate planes also gives the same answer. I use a trapezoid accumulation to do this calculation from civil engineering. I find this mathematically unsatisfying and at odds with the idea that, as an element shrinks in size, its importance increases. I therefore rescale each edge around a vertex by the inverse square of its length before this accumulation. It lights smooth surfaces more smoothly. It can interfere with art direction.