# positioning a cylinder in 3d

i have problem in positioning a cylinder at appropriate pposition in 3d-

in below code i just want to join two sphere by rotating a cylinder firstly with y axis then with x axis.

but my problem is that cylinder is not going to it’s appropriate position or it’s rotating perfectly

my code

glColor3f( 1.0, 0.3, 0.0 );
glutWireSphere( 0.1, 125, 125 );

glPushMatrix();
glTranslatef( 1.0, 1.0, -1.0 );
glColor3f( 1.0, 0.9, 0.7);
glutWireSphere( 0.1, 100, 100);
glPopMatrix();

glRotatef( 45, 1.0, 0.0, 0.0 );
glPushMatrix();
glRotatef( 135, 0.0, 1.0, 0.0 );
glColor3f( 1.0, 1.0, 1.0 );
gluCylinder(quadObj, 0.03, 0.03, 1.732, 20, 10);
glPopMatrix();

should i give the whole code

plz reply me solution …thanks

i have problem in positioning a cylinder at appropriate position in 3d-

in below code i just want to join two sphere by rotating a cylinder firstly with y axis then with x axis.

but my problem is that cylinder is not going to it’s appropriate position or it’s rotating perfectly

my code

glColor3f( 1.0, 0.3, 0.0 );
glutWireSphere( 0.1, 125, 125 );

glPushMatrix();
glTranslatef( 1.0, 1.0, -1.0 );
glColor3f( 1.0, 0.9, 0.7);
glutWireSphere( 0.1, 100, 100);
glPopMatrix();

glRotatef( 45, 1.0, 0.0, 0.0 ); // rotation with x axis
glPushMatrix();
glRotatef( 135, 0.0, 1.0, 0.0 ); //rotation with y axis
glColor3f( 1.0, 1.0, 1.0 );
gluCylinder(quadObj, 0.03, 0.03, 1.732, 20, 10);
glPopMatrix();

should i give the whole code

thanks

plz reply the solution…
i m still fighting for it

thanks

I posted a demo that does this a while ago. The source code is at:

Orient Tube Demo - MaxH

thank you for ur help… i m trying now
nd will let u know

thanks a lot

Hey MaxH, great demo. I really need to know the maths you come around to put all these pieces together, any guidance? Thanks

There are really only 3 lines of math in the demo, where I solve for m, az, and el. These relations are very similar to converting from Cartesian to Spherical coordinates. A diagram explains it best. See the link below …

Cartesian To Spherical Coordinates

I start with a vector parallel to the X axis and rotate it in azimuth and elevation to point it in the correct direction.

Thanks :), I am checking it out.