View Full Version : Calculation of normals

Ramesh

12-18-2000, 03:25 AM

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).]

Spaceman

12-18-2000, 04:24 AM

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=(v1y*v2z - v1z*v2y);

n1y=(v1z*v2x - v1x*v2z);

n1z=(v1x*v2y - v1y*v2x);

/divide the normal through its length

n1x/=sqrt(n1x*n1x+n1y*n1y+n1z*n1z);

n1y/=sqrt(n1x*n1x+n1y*n1y+n1z*n1z);

n1z/=sqrt(n1x*n1x+n1y*n1y+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).]

Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.