3d formula for solid tube / pipe


can someone tell me the formula for creating 3D tubes? (For example, to simulate a snake, pipes or a tube)

I´ve tried to figure it out on paper, but i´m not sure how to put it into practive…

Would be glad if you could give me some hints or a link to a website!


first of all- that’s not so advanced (someone else would have said that, if not me :smiley: )

secondly- if it’s a straight cylinder, it could look like this:

void DrawCylinder(float R1, float R2, float H) {
 int    i, j, steps = 32;
 float  phi, dphi = 2.*M_PI / (float)(steps);


 glOrtho(-10., 10., -10., 10., 1., 100.);

 gluLookAt(10., 10., 5., 0., 0., 0., 0., 0., 1.);



 for(i = 0, phi = 0.; i <= steps; i ++, phi += dphi) {

        if((i%2) == 0)
                glColor3f(1., 0., 0.);
                glColor3f(0., 1., 0.);

        glVertex3f(R1*cos(phi), R1*sin(phi), -H/2.);
        glVertex3f(R2*cos(phi), R2*sin(phi),  H/2.); }

 glEnd(); } 

if R1==R2 it is a cylinder, otherwise a cone. you can use glTranslatef/glRotatef/glScalef to put it at any position you want .


Thanks for your answer… but i don´t want a plain cylinder…

I mean a curved cylinder - which is build from a path of points… i think this is slighly more advanced. I have code for a plain cylinder already in my app but i don´t know how to realize the curved cylinder.

i recall the graphics gems series has something on the line… game prog gems too.

well, starting from a 3D path made of points, naively I would start by taking the first segment, finding the perpendicular plane, generating some 16/64 points along a circle, take the second segment, do the same and also connect the first series of points to the second… an so on.

if the path do not bend or twist too much, it gives good results… otherwise look for fiber bundles / hopft fibration applied to graphics.

tomorrow i will be more specific. :slight_smile:

Well, easiest would be to do a curve, e.g. Bezier or Catmul-Rom and then generate the Frenet frame at each segment and connect circles transformed by it.