# Getting the normals of a hemisphere?

I'm trying to calculate the normal for a hemisphere.

I draw the hemi-sphere by this code:

``````for(float phi = 0.0; phi < 1.567; phi += factor) {

for(float theta = 0.0; theta < 2*3.14 + factor; theta += factor)
{
x = rh * sin(phi) * cos(theta);
z = rh * sin(phi) * sin(theta);
y = -rh * cos(phi);

gl::vertex(Vec3f(x, y, z));

x = rh * sin(phi + factor) * cos(theta);
z = rh * sin(phi + factor) * sin(theta);
y = -rh * cos(phi + factor);

gl::vertex(Vec3f(x, y, z));

}
glEnd();
}
``````
-
Do you want smooth or hard edges? – stephelton Apr 17 '12 at 19:57
can you tell me in both cases ? – Moaz Apr 17 '12 at 20:18
eBusiness has the right way for smooth edges. Smooth edges would be a bit more difficult (ask if you really care for them...) – stephelton Apr 17 '12 at 20:45
-1 this shows no research effort. It has nothing to do with being new to OpenGL, this is a basic math question that could easily be found with a little research. – Byte56 Apr 17 '12 at 20:58

Same way you get the normals of a sphere, the vector from the centre to any surface point is a normal for that surface point. For a lot of uses you probably want them normalized, but that is all there is to it. Just remove the `rh` factor from your position calculations and you get the normalized normals.

Spheres turn out to be mathematical entities that are incredibly easy to work with.

-
But after removing the rh factor, how to set the radius of the sphere?. Should I calculate the normals In both sections of the codes that draw the spheres ie. x = rh * sin(phi) * cos(theta); z = rh * sin(phi) * sin(theta); y = -rh * cos(phi); gl::vertex(Vec3f(x, y, z)); – Moaz Apr 17 '12 at 20:44
@AhmedSaleh You'll have to separate the two calculations, one for the position and one for the normal, the mathematics just happen to be identical except for the position needing the radius factor. – aaaaaaaaaaaa Apr 17 '12 at 20:55