how to calculate normals for a circle??

with reference to my earlier posting(,

  1. can anybody tell me how to calculate normals for a circle?
  2. Is it possible to move the light position along with view point?
  3. I’m trying to create an effect like this - holding a searchlight(spotlight) in hand and moving into a dark tunnel.

I checked nehe’s demo on lighting and specular lighting and i tried out in the same way. But there is no effect of lighting. if possible, will you guys tell me what sort of components(global ambient light or ambient and diffuse of LIGHT0 or GL_SPOT_DIRECTION or GL_SPOT_CUTOFF etc.) to get the above mentioned effect.

Many may thanks in advance

known quantity - centre of the circle.

As far as I know circle was flat figure so the normal is in the same direction(s) (to both sides so you must choose one ) as normal from plane holding this circe. You can get the normals mathematicaly by using 3 points of cirle, creating 2 vectors from them & calculating cross product from those vectors

or do you mean normals extruding outward from the centre?

Originally posted by Gavin:
or do you mean normals extruding outward from the centre?

He wants the normals pointing inside for lighting a cylinder on the inside.
I tried to tell him how to do this in his original thread and I have no idea why he started this one.
Perhaps he does not like my answers

[This message has been edited by satan (edited 12-11-2002).]

I think satan already gave you this basic formula, but calculating the normal for any given point on a circle is easy. You obviously know the center, and you need to know the point on the circle you need to calculate the normal for, or else how do you know what to pass to glVertex3f?

Anyway, say that vert is the vertex on the circle, and center is the center. You calculate the normals something like so:

This will calculate normals pointing in, to calculate normals pointing out, you simply reverse the order you subtract.

norm.x = center.x - vert.x;
norm.y = center.y - vert.y;
norm.z = center.z - vert.z;

Then you set the normal to a lenght of 1 by doing something like so:

len = sqrt(norm.xnorm.x + norm.ynorm.y + norm.z*norm.z);

norm.x /= len;
norm.y /= len;
norm.z /= len;

Nearly, I explained it for a circle at the origin and told him that the center is just an offset to this.
To complicated???
Perhaps I should not think that people starting OGL know vector math

once again special apologies to SATAN.
since my pc crashed i couldn’t respond.

I started this thread to ask the following question
2. Is it possible to move the light position along with view point?
but i mixed up and typed everthing.

sorry guys.

Actually i’m confused about how to specify normals because already i specified the normals in the way you guys said. But the lighting effect was different one.

Here is my coding for lighting and draw functions


GLfloat globalambient[]={0.830,0.830,0.830,1.0},
ambient0[]={0.30,0.30,0.30,1.0}, shine=5.0,
pos0[]={camera aim(x),camera aim(y),camera aim(z),1.0};





int INCR=1,i;
double ax,ay,az,bx,by,bz,cx,cy,cz,dx,dy,dz;
float veclen=0,veclen2=0;
for (i=0;i<360;i=i+INCR)







x1,y1,z1-centre of circle1
x2,y2,z2-centre of circle2
ang1,ang2 - angle of the plane which holds the circles with respect to world cooordinates
r1,r2-radius of circles

method of drawing the tunnel
using centre points & radius, vertices of circles are calculated and they are joined by polygons

now my problem I can’t get the lighting effect with shades and shininess of the surface

Hope everybody understood what my problem is.


1)Be extra careful if you seperate lighting setup from rendering. If you update your modelview/projection matrices, you may need to update your light position. Depends on what you want to accomplish.

Submitting a light position once and keeping it through matrix updates kind of makes your light ‘attached to the camera’.

If you want your light position to be fixed relative to the scene, you’ll have to respecify the light position each time after updating matrices, and before actually rendering the geometry.

2)My wild guess regarding your problem: Your sphere is centered around the origin. Your light is positioned at the origin. All normals point to the origin. Result? All surfaces get the exact same light intensity, thus no shades and lighting looks as if it doesn’t work.

Try moving your light position around and see if it’s getting better. You may also need to experiment with the light’s falloff parameters, but try changing position first.

Actually i’m moving my light along with camera position.

the object is a dark tunnel.

the effect i want is

3. I’m trying to create an effect like this - holding a searchlight(spotlight) in hand and moving into a dark tunnel.

normals point away from light position

I haven’t taken a close look at your code yet, but I don’t think you don’t want all the normals to point away from your light source. If I understand correctly what you want, you want them all to point IN towards the center of the cylinder.

Terrible ASCII art example viewing cylinder along edge:

| | | |
v v v v
—L---------------- <- center path through cylinder
^ ^ ^ ^
| | | |

The Xs above represent the location of vertices on the top and bottom of the cylinder, the L represents the location of your Light, the center line being the path the light is moving. the lines coming off the Xs are the direction you want the normals pointing. Note they are pointing in TOWARDS THE CENTER LINE, NOT THE LIGHT.

Hope that helps somewhat.

Edit: Ugh. I hate how the code tags sometimes choose to use different font sizes in different spots.

[This message has been edited by Deiussum (edited 12-17-2002).]