1. ## Calculating Surface Normals

Here's my situation:

Let's say I have 3 verticies: v1,v2 and v3.

how would I calculate a surface normal?

assume that when the points are laballed counter-clockwise relative to you, the normal vector points towards you.

example:

v1

v2

v3

the normal would be coming straight at you.

how would I calculate the exact surface normal vector using the 3 sets of x,y, and z values?

2. ## Re: Calculating Surface Normals

take the cross product... and by right hand rule the normal would face towards you.

cross product can also be seen as the determinant of these three vectors:

<i,j,k>
<v2-v1>
<v3-v1>

correct me if I am wrong... it's been a little while

3. ## Re: Calculating Surface Normals

You simply do (in pseudocode) :

rx1=v1x-v2x
ry1=v1y-v2y
rz1=v1z-v2z
rx2=v3x-v2x
ry2=v3y-v2y
rz2=v3z-v2z

nx=ry1*rz2-rz1*ry2
ny=rz1*rx2-rx1*rz2
nz=rx1*ry2-ry1*rx2

Ok, now we have to normalize it (make length 1) :

len=sqrt(nx*nx+ny*ny+nz*nz)
if (len>0) {
nx*=(1/len)
ny*=(1/len)
nz*=(1/len)
} else {
/* oops, you've got a problem */
}

That should be it. Enjoy

Note : this might be for clockwise, I simply ripped it from some working code of mine. Simply invert the normal for counterclockwise if that's the case.

4. ## Re: Calculating Surface Normals

Thanks, guys!

I actually just picked up an Algebra & Geometry textbook from my math teacher today, and got the necessary math from there. but thanks anyway!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•