# Thread: positioning a cylinder in 3d

1. ## 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

2. ## Re: positioning a cylinder in 3d

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

3. ## Re: positioning a cylinder in 3d

i m still fighting for it

thanks

4. ## Re: positioning a cylinder in 3d

Originally Posted by somnath
plz reply the solution.. i m still fighting for it
I posted a demo that does this a while ago. The source code is at:

Orient Tube Demo - MaxH

5. ## Re: positioning a cylinder in 3d

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

thanks a lot

6. ## Re: positioning a cylinder in 3d

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

7. ## Re: positioning a cylinder in 3d

I really need to know the maths you come around to put all these pieces together, any guidance?
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.

8. ## Re: positioning a cylinder in 3d

Thanks , I am checking it out.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•