Thread: Attaching Cylinder to Bezier curve...

  1. #1
    the Wizard
    Join Date
    Aug 2004
    Posts
    109

    Attaching Cylinder to Bezier curve...

    I've been studying bezier curves for some time now, and I want to attach a cylinder to the bezier curve, to make some kind of tunnel, but I can't figure out how.. Can somebody give me a little help on a way?
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    More information is definitely needed, but I'll take a stab at it anyways. Think about it like this, given a time t on a curve that varies between [0,1], you need to find the tangent to that point and use that info to create a cylinder. Is your curve 2D or 3D? If 3D is it on the X-Z plane? Surely you have a fixed number of points representing your curve at evenly spaced intervals. If you do not, look up "Arc Length Parameterization". Then, you can go to each one of these points and calculate the geometry of the slice of the cylinder that will make up the tunnel. Once you go all the way through the curve, from 0 to 1, then simply connect up the tunnel points using triangles. Hopefully this helps you some. If you get stuck let me know.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You could also use some sort of SLERP or spherical linear interpolation between points on the cylinder and points on the curve. This would yield a new point and you would simply insert this point into the list. When drawn the objects will be merged. You can also choose by how much you want to interpolate. Small interpolations will result in many many points being generated and will produce a globular joining of the two objects but might be slower than death to render. On the other hand you might suffer some jaggedness with higher interpolation values...but it also might be real-time.

    Incidentally SLERP works best with quaternions. But you can code it like this:


    double LI(double v1,double v2,double f1)
    {
    return v1+f1*(v2-v1);
    }


    Then a lerp would be:

    newpointx=LI(vertex1x,vertex2x,lerpfactorx);
    newpointy=LI(vertex1y,vertex2y,lerpfactory);
    newpointz=LI(vertex1z,vertex2z,lerpfactorz);

    but a SLERP is:

    slerpvalue=LI(LI(v1,v2,slerpfactor1),LI(v3,v4,sler pfactor2),LI(slerpfactor1,slerpfactor2,slerpfactor 3));

    If you notice this will gradually produce a curve as slerpfactor1 moves towards slerpfactor2 or as slerpfactor3 varies from 0 to 1. These new points can be inserted as they are created and then you can triangulate the mess and you should have nicely merged objects.
    Last edited by VirtualAce; 09-01-2004 at 11:51 PM.

  4. #4
    the Wizard
    Join Date
    Aug 2004
    Posts
    109
    Thx alot both Now I have something to go on with

    MrWizard:
    I want to create a 3D tunnel, on the Z plane, are there any differences because I want the camera to follow the bezier curve in the middel, so does it make any difference?
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

  5. #5
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by MipZhaP
    Thx alot both Now I have something to go on with

    MrWizard:
    I want to create a 3D tunnel, on the Z plane, are there any differences because I want the camera to follow the bezier curve in the middel, so does it make any difference?
    it makes no differece as long as your consistent. in fact, the tunnel could curve in any direction as long as the camera follows the tangent at each point.

  6. #6
    the Wizard
    Join Date
    Aug 2004
    Posts
    109
    Also my thought
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using basic library to write curve to bmp
    By CIO in forum C Programming
    Replies: 3
    Last Post: 02-21-2009, 02:25 PM
  2. Bezier Curves where y = f(x)
    By thetinman in forum Game Programming
    Replies: 11
    Last Post: 12-27-2008, 10:21 AM
  3. Collision detection between bezier and ball.
    By CornedBee in forum Game Programming
    Replies: 1
    Last Post: 04-27-2006, 12:49 PM
  4. Bezier curve
    By simo in forum Windows Programming
    Replies: 2
    Last Post: 12-11-2005, 03:01 AM
  5. Bezier surfaces
    By Sang-drax in forum Game Programming
    Replies: 6
    Last Post: 11-08-2004, 05:18 PM