Hi
How can I calculate normal to a polygon?
Assume that I have a polygon of vertices v1,v2,v3,v4.
Can you give me some info.
thanks
[This message has been edited by Ramesh (edited 12-18-2000).]
Hi
How can I calculate normal to a polygon?
Assume that I have a polygon of vertices v1,v2,v3,v4.
Can you give me some info.
thanks
[This message has been edited by Ramesh (edited 12-18-2000).]
For flat polygons you only need one normale because its everywhere the same.
Take 3 Points of you Surface, for example a,b,c and make two vectors:
/calculate the vector v1
v1x=bx-ax
v1y=by-ay
v1z=bz-az
/calculate the vector v2
v2x=cx-ax
v2y=cy-ay
v2z=cz-az
/do the cross product with v1 and v2
n1x=(v1yv2z - v1zv2y);
n1y=(v1zv2x - v1xv2z);
n1z=(v1xv2y - v1yv2x);
/divide the normal through its length
n1x/=sqrt(n1xn1x+n1yn1y+n1zn1z);
n1y/=sqrt(n1xn1x+n1yn1y+n1zn1z);
n1z/=sqrt(n1xn1x+n1yn1y+n1z*n1z);
/…and put the normal in the glNormal function
glNormal3f(n1x,n1y,n1z);
If the polygon isn’t flat (with a minimum of 4 points) you need to calculate the normal of every edge with the vector before and after every vertex
[This message has been edited by Spaceman (edited 12-18-2000).]