Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: 3d formula for solid tube / pipe

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2005
    Posts
    4

    3d formula for solid tube / pipe

    Hi,

    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!

    Thanks
    Malakai

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    664

    Re: 3d formula for solid tube / pipe

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

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

    Code :
    void DrawCylinder(float R1, float R2, float H) {
     int    i, j, steps = 32;
     float  phi, dphi = 2.*M_PI / (float)(steps);
     
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     glOrtho(-10., 10., -10., 10., 1., 100.);
     
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
     gluLookAt(10., 10., 5., 0., 0., 0., 0., 0., 1.);
     
     glEnable(GL_DEPTH_TEST);
     glShadeModel(GL_FLAT);
     
     glBegin(GL_TRIANGLE_STRIP);
     
     for(i = 0, phi = 0.; i <= steps; i ++, phi += dphi) {
     
            if((i%2) == 0)
                    glColor3f(1., 0., 0.);
            else
                    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 .

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2005
    Posts
    4

    Re: 3d formula for solid tube / pipe

    Hello,

    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.

  4. #4
    Member Regular Contributor
    Join Date
    Feb 2000
    Location
    milano, italy
    Posts
    288

    Re: 3d formula for solid tube / pipe

    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.
    Dolo/\/\ightY

  5. #5
    Member Regular Contributor
    Join Date
    Mar 2001
    Posts
    466

    Re: 3d formula for solid tube / pipe

    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.

Posting Permissions

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