# Thread: Attaching Cylinder to Bezier curve...

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

2. 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.

3. 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.

4. 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?

5. 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. Also my thought