# How to fill the inner lattitude circles in a sphere?

I need to draw a sphere that has half of the surface of one color and half of another color. At the moment, I am using glusphere with a texture and is fine. My problem is that I would like to fill the inner latitudal circles like in the attached image . I suppose that by using glusphere I cannot do that. That is why I was thinking in drawing the sphere using vertexes like the code that I attach here. In that code the first for loop increments by lat/4 so you will only see 4 circles (just to test). Circles inside are filled fine but,

[ol]
[li]How can I paint the outer surface between that circles?
[/li][li]Is there any way to agroup all vertexes so I just need to call traslate and rotate once?
[/li][li]Do you think in a better way to do what I want?
[/li][/ol]

My solution needs to run in a PC as an animation. I am using JOGL.
[ATTACH=CONFIG]1429[/ATTACH]

``````
float rgba[] = {1f,0f,0f};

gl.glMaterialfv(GL.GL_FRONT, GL2.GL_AMBIENT, rgba, 0);
gl.glMaterialfv(GL.GL_FRONT, GL2.GL_SPECULAR, rgba, 0);
gl.glMaterialf(GL.GL_FRONT, GL2.GL_SHININESS, 1f);
gl.glEnable(gl.GL_POLYGON_SMOOTH);
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, gl.GL_FILL);

int r=1;
int lats = 64;
int longs = 64;

int i, j;
for(i = 0; i <= lats; i+=lats/4) {
double lat0 = Math.PI * (-0.5 + (double) (i - 1) / lats);
double z0  = Math.sin(lat0);
double zr0 =  Math.cos(lat0);

double lat1 = Math.PI * (-0.5 + (double) i / lats);
double z1 = Math.sin(lat1);
double zr1 = Math.cos(lat1);

gl.glBegin(gl.GL_POLYGON);
for(j = 0; j <= longs; j++) {
double lng = 2 * Math.PI * (double) (j - 1) / longs;
double x = Math.cos(lng);
double y = Math.sin(lng);

gl.glNormal3d(x * zr0, y * zr0, z0);
gl.glVertex3d(x * zr0, y * zr0, z0);
gl.glNormal3d(x * zr1, y * zr1, z1);
gl.glVertex3d(x * zr1, y * zr1, z1);
}
gl.glEnd();
}
``````

I suppose that by using glusphere I cannot do that.

Actually, with a little bit of finagling you can accomplish your goal using gluSpheres.
An example with image and code is attached …

[ATTACH=CONFIG]1430[/ATTACH]

``````
void Carmine_Spheres (void)
{
static int first = 1;
static double north = {0.0, 0.0, -1.0,  0.2}, south = {0.0, 0.0,  1.0,  0.2};
static GLUquadricObj *YEL, *GRN;

if (first)  {
first = 0;
}

glEnable  (GL_LIGHTING);

// Whole yellow sphere on left (-X).

glDisable (GL_CLIP_PLANE0);
glDisable (GL_CLIP_PLANE1);

glPushMatrix ();
glTranslatef (-1.5, 0.0, 0.0);
glColor3f (0.90, 0.90, 0.30);
gluSphere (YEL, 0.7, 36, 18);
glPopMatrix ();

// Clipped green sphere on right (+X).

glEnable (GL_CLIP_PLANE0);
glEnable (GL_CLIP_PLANE1);

glPushMatrix ();
glTranslatef (1.5, 0.0, 0.0);
glColor3f (0.20, 0.70, 0.20);
glClipPlane (GL_CLIP_PLANE0, north);
glClipPlane (GL_CLIP_PLANE1, south);
gluSphere (GRN, 0.7, 36, 18);
glPopMatrix ();

// Combined spheres in center.
// Use polygon offset to prevent z fighting.

glEnable (GL_POLYGON_OFFSET_FILL);

glPushMatrix ();
glColor3f (0.20, 0.70, 0.20);   // Clipping still enabled here.
gluSphere (GRN, 0.7, 36, 18);
glPopMatrix ();

glDisable (GL_CLIP_PLANE0);
glDisable (GL_CLIP_PLANE1);

glDisable (GL_POLYGON_OFFSET_FILL);

glColor3f (0.90, 0.90, 0.30);
gluSphere (YEL, 0.7, 36, 18);
}

``````

[QUOTE=Carmine;1285233]Actually, with a little bit of finagling you can accomplish your goal using gluSpheres.
An example with image and code is attached …

[ATTACH=CONFIG]2321[/ATTACH]

``````
void Carmine_Spheres (void)
{
static int first = 1;
static double north = {0.0, 0.0, -1.0,  0.2}, south = {0.0, 0.0,  1.0,  0.2};
static GLUquadricObj *YEL, *GRN;

if (first)  {
first = 0;
}

glEnable  (GL_LIGHTING);

// Whole yellow sphere on left (-X).

glDisable (GL_CLIP_PLANE0);
glDisable (GL_CLIP_PLANE1);

glPushMatrix ();
glTranslatef (-1.5, 0.0, 0.0);
glColor3f (0.90, 0.90, 0.30);
gluSphere (YEL, 0.7, 36, 18);
glPopMatrix ();

// Clipped green sphere on right (+X).

glEnable (GL_CLIP_PLANE0);
glEnable (GL_CLIP_PLANE1);

glPushMatrix ();
glTranslatef (1.5, 0.0, 0.0);
glColor3f (0.20, 0.70, 0.20);
glClipPlane (GL_CLIP_PLANE0, north);
glClipPlane (GL_CLIP_PLANE1, south);
gluSphere (GRN, 0.7, 36, 18);
glPopMatrix ();

// Combined spheres in center.
// Use polygon offset to prevent z fighting.

glEnable (GL_POLYGON_OFFSET_FILL);

glPushMatrix ();
glColor3f (0.20, 0.70, 0.20);   // Clipping still enabled here.
gluSphere (GRN, 0.7, 36, 18);
glPopMatrix ();

glDisable (GL_CLIP_PLANE0);
glDisable (GL_CLIP_PLANE1);

glDisable (GL_POLYGON_OFFSET_FILL);

glColor3f (0.90, 0.90, 0.30);
gluSphere (YEL, 0.7, 36, 18);
}

``````

[/QUOTE]

I think you missunderstood me. I want a sphere yes but, if I make a cut on this sphere, still I want to see the “latitude planes” of inside filled with a color. For example, if I make a cut to make 2 halfs, I will see 2 half of spheres that will be closed objects as the plane of the middle latitude is filled. In my case, I can archieve this using the above code for creating the inner planes and superposing a glushpere but I though there must be something better…

I think you missunderstood me. I want a sphere yes but, if I make a cut on this sphere, still I want to see the “latitude planes” of inside filled with a color. For example, if I make a cut to make 2 halfs, I will see 2 half of spheres that will be closed objects as the plane of the middle latitude is filled. In my case, I can archieve this using the above code for creating the inner planes and superposing a glushpere but I though there must be something better…
There are 3 spheres in my figure. The left and right spheres are only there to clarify my approach. The central sphere is the final product. Is this not what you asked for? If not, I don’t know what you want (even with your second explanation). Can you include a picture of the end product of what you need, or something very similar to it? I thought you were asking for a solid sphere with the mid-latitudes a different color from the polar regions.

Sorry for all. I hope this picture is going to be clear for you: http://oi66.tinypic.com/2h31ji8.jpg (i’m getting problems to upload image/urls to the forum)

Green are inner circles following the lat lines of the sphere that are filled and outside there is a blue sphere. I can do this drawing each filled circle + glusphere but it is like drawing twice the points required. Is there any trick?

PS. blue sphere should be full draw of course, I just draw here a portion to see the interior.

blue sphere should be full draw of course, I just draw here a portion to see the interior.

If the blue sphere is full, you wouldn’t see any of the green circles because they would be totally inside the sphere?

Exactly! From outside I would not see anything. But, as I want to do 2D projections, I would see. When I say 2D projection I mean, I choose for example plane XY and then I look only in a region between 2 and 2.1 of Z with ortho view. If the sphere is r=1 and it is centered at 2, with my previous example I would see an empty circle but I want to see it full. That is why I wanted to paint also the inner circles of the sphere.

If you’re goal is to make it clear which is the inside and outside surfaces of a sphere, I think there are better ways than what I’ve done below. Actually, I’ve done two things below. One is to make the inside and outside surfaces of the sphere different colors. That combined with enabling lighting shows which surfaces are inside and outside. I’ve also put in the latitude circles you wanted. This is done using gluDisk and gluSphere. That way you don’t have to mess around with vertex computations. Don’t worry too much about efficiency until you get hundreds of thousands of vertices.

[ATTACH=CONFIG]1431[/ATTACH]

``````
//--+----4----+----3----+----2----+----1----+----|----+----1----+----2----+----3----+----4----+----5
//---------------------------------------   Carmine_Disk   -----------------------------------------

void Carmine_Disk (void)
{
static short first = 1;

if (first)  {
first = 0;
}

glDisable (GL_CULL_FACE);

gluDisk (DSK, 0.0, 0.99, 36, 1);
}

//--+----4----+----3----+----2----+----1----+----|----+----1----+----2----+----3----+----4----+----5
//-------------------------------------   Carmine_Spherex   ----------------------------------------

void Carmine_Spherex (void)
{
static int first = 1;
static float h, b;
static double front = {0.0, 1.0, 0.0, 0.0};

if (first)  {
first = 0;
b = cos (45.0 / RADDEG);
h = sin (45.0 / RADDEG);
}

glEnable (GL_LIGHTING );
glEnable (GL_CULL_FACE);

// Outer sphere surface (yellow).

glClipPlane (GL_CLIP_PLANE0, front);
glEnable (GL_CLIP_PLANE0);

glCullFace (GL_BACK);

glColor3f (0.90, 0.90, 0.30);
gluSphere (FRN, 1.0, 36, 18);

// Inner sphere surface (orange).

glCullFace (GL_FRONT);
glColor3f (0.60, 0.30, 0.00);
gluSphere (FRN, 1.0, 36, 18);

glDisable (GL_CLIP_PLANE0);

// Latitude planes (blue).

glColor3f (0.20, 0.50, 0.80);
Carmine_Disk ();

glPushMatrix ();
glTranslatef (0, 0, h);
glScalef (b, b, b);
Carmine_Disk ();
glPopMatrix ();

glPushMatrix ();
glTranslatef (0, 0, -h);
glScalef (b, b, b);
Carmine_Disk ();
glPopMatrix ();
}

``````