Yet another How to find Normal of a triangle thread!
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
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
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
<br>[v2x-v1x v2y-v1y v2z-v1z]<br>[v2x-v3x v2y-v3y v2z-v3z]<br></pre><br><br>= ((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<br><br>So the x portion of the vector is: ((v2y-v1y)*(v2z-v3z)-(v2z-v1z)*(v2y-v3y))<br>The y portion is: -((v2x-v1x)*(v2z-v3z)-(v2z-v1z)*(v2x-v3x))<br>The z portion is: ((v2x-v1x)*(v2y-v3y)-(v2y-v1y)*(v2x-v3x))<br><br>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')<br><br>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:<br><br>sqrt(x*x + y*y + z*z)<br><br>
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.
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.
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 OmniscientN00b
Hope someone helps.
Somebody did.
Quote:Original post by erissian
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 OmniscientN00b
Somebody did.
So those are the normal vertices right?
Excellent I will try those.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement