Jump to content
  • Advertisement
Sign in to follow this  

Geometry: how to define the vertices of a tunnel around a given path

This topic is 2904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to create some kind of demo that rushes through a tunnel.

I have made a random path generator that creates smooth looking paths in 3D space (just some 3D points)

Now I would like to create polies that form a tunnel around that path.

To give an example, let us assume that the path only extends towards the Z axis.
(so path_pos.x and path_pos.y will remain 0)

then I could define the positions of the vertices as:

x = path_pos.x + cos(t)*radius;
y = path_pos.y + sin(t)*radius;
z = path_pos.z;

However, as mentioned before, I would like the polies to form a smooth tunnel around that path,
and the path rotates to the x and y axis as it progresses.

This means that we have to adjust the formula, else it would start looking deformed, and
the radius of the tunnel would be depending on the angles between the path points...

(See the given image, the small green circles represent the path points,
and the red lines represent circles on which I have to define the points of the polies)
(first image is the problem rendered with 3dsmax,
second and third are images made with paint to represent the problem more mathematically)

images: http://www.dropbox.com/gallery/22326841/1/Tunnel_Problem?h=293d6e

As we can see from the image, the x and y component from path_pos2
could actually be the same than the ones from path_pos1,
with a different Z component for every point in the circle.

I could define the following:

z = path_pos.z + ( ( cot( (anglebetween([p1,p2],[p2,p3])/2 ) * (radius*2) ) *
( (radius*2)/(radius+(y-p2.y)) ) );

But I think this is only the case because the line(path_pos1,path_pos2) is parallel to the Z axis.

When the path starts making 'rotations'/'turns', both around x(pitches) and y(yaws) axis,
I'm not sure how to define the points around the pathpoint that should form an ellipse,
so that the radius of the tunnel would remain the same (except in the actual corners, for efficiency).

I really hope this doesn't sound like a shitstorm, I tried my best to explain...
Could anyone please help? :)

Share this post

Link to post
Share on other sites
Hi Xcrypt,

This is an interesting problem. As a suggestion (hopefully to get feedback from others), you could try an iterative approach. Triangulating the cylinder around an arbitrary curve seems tricky to me, so I would start by creating a triangulated cylinder around a straight line. The straight line would be made up of the same number and length of line segments you want in the final path. Then you could gradually transform the straight line to the desired path. At each step you would reinforce the constraint that the vertices of the triangulated surface around the line maintain a minimum distance from the line.

The final mesh is going to need to be cleaned up a bit since this process does nothing to maintain good scaling of the triangles. But at least things are more-or-less in the right place.


Share this post

Link to post
Share on other sites
Similar problems has already been discussed in the past in this forum. I suggest to first calculate a rough tunnel using the parallel transport method and then get a smoother version using some kind of subdivision method.

The parallel transport algorithm is quite simple. You first define a frame at the first point of the curve such that the vectors are the desired tangent, normal and binormal of the curve at that point. For each successive point you then define a new tangent using some method (for example normalizing the difference between the next and the previous point) and a new binormal as the cross product of the previous tangent and the new tangent (you do not normalize it immediatly). If the length of the binormal is zero (the two tangents are parallel) you simply copy the previous frame, otherwise you normalize the binormal and rotate the old normal around the binormal by the same angle between the old and the new tangent to compute the new normal. You should then recompute the binormal (because the frame may have changed its orientation). You may find a better description with pseudocode in this paper. The main advantage over computing Frenet Frames are that the parallel transport method preserves the orientation of the frames and it also works with singularities.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!