Yet another How to find Normal of a triangle thread!

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

Recommended Posts

My mind over heating... since days... I've read numerous articles Is there a readily available function that returns a normal vertex taking in 3 vertices? void vertnormal(float v1x,float v1y,float v1z,float v2x,float v2y,float v2z,float v3x,float v3y,float v3z,float *nx,float *ny,float *nz) { //Here goes the code that does all calculations which I donot know! :< *nx = valuex; *ny = valuey; *nz = valuez; } Could someone post such a similar function? Thankxs

Share on other sites
Three vertices form two vectors, right?
The cross product of two vectors forms the normal.

So, vector 1 = <v2x-v1x, v2y-v1y, v2z-v1z>
And, vector 2 = <v2x-v3x, v2y-v3y, v2z-v3z>

Then, take the cross product

[   i         j         k   ][v2x-v1x  v2y-v1y    v2z-v1z][v2x-v3x  v2y-v3y    v2z-v3z]

= ((v2y-v1y)*(v2z-v3z)-(v2z-v1z)*(v2y-v3y))i - ((v2x-v1x)*(v2z-v3z)-(v2z-v1z)*(v2x-v3x))j + ((v2x-v1x)*(v2y-v3y)-(v2y-v1y)*(v2x-v3x))k

So the x portion of the vector is: ((v2y-v1y)*(v2z-v3z)-(v2z-v1z)*(v2y-v3y))
The y portion is: -((v2x-v1x)*(v2z-v3z)-(v2z-v1z)*(v2x-v3x))
The z portion is: ((v2x-v1x)*(v2y-v3y)-(v2y-v1y)*(v2x-v3x))

Of course, the issue is that the vector can go two ways (positive and negative direction), so make sure you know which way your triangle is facing (as in, which way is 'out')

Also, if you want to 'normalize' (make of size 1) the vector, divide each part of the vector by the size of the vector, which is:

sqrt(x*x + y*y + z*z)

Share on other sites
I donot do OPENGL or direct x programming...

I just need a plain C function.. More over I am not so goood in vectors.. I donot know what cross product is.

Hope someone helps.

Share on other sites
Quote:
 Paraphrased from visage x = (v2y-v1y)*(v2z-v3z)-(v2z-v1z)*(v2y-v3y);y = -(v2x-v1x)*(v2z-v3z)+(v2z-v1z)*(v2x-v3x);z = (v2x-v1x)*(v2y-v3y)-(v2y-v1y)*(v2x-v3x);r = sqrt(x*x + y*y + z*z);x /= r;y /= r;z /= r;

Quote:
 Original post by OmniscientN00bHope someone helps.

Somebody did.

Share on other sites
Quote:
 Original post by erissianx = (v2y-v1y)*(v2z-v3z)-(v2z-v1z)*(v2y-v3y);y = -(v2x-v1x)*(v2z-v3z)+(v2z-v1z)*(v2x-v3x);z = (v2x-v1x)*(v2y-v3y)-(v2y-v1y)*(v2x-v3x);r = sqrt(x*x + y*y + z*z);x /= r;y /= r;z /= r;

Quote:
 Original post by OmniscientN00bSomebody did.

So those are the normal vertices right?
Excellent I will try those.

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• Forum Statistics

• Total Topics
633407
• Total Posts
3011700
• Who's Online (See full list)

There are no registered users currently online

×