Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Geometry: problem with defining the vertices of a tunnel around a given path

  1. Nov 2, 2011 #1
    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 garbagestorm, I tried my best to explain...
    Could anyone please help? :)
    Last edited: Nov 2, 2011
  2. jcsd
  3. Nov 5, 2011 #2
    I think you'd be better off not trying to do it in two steps, i.e. creating the points on the path first, then trying to create the tunnel. Instead, think about one object, which is your center point, surrounded by some number of points equidistant from it and in all lying in the same plane. So for example the point (0,0,0) together with points (cos(k), sin(k), 0) where k goes in steps from 0 to 2pi. That all lives in the x-y plane.

    Now to make your path, you want to sweep this plane around in 3D space. If you move the whole plane rigidly and in discrete steps, you'll get what you have now, which is a problem: the tunnel's cross section will become elliptical whenever the motion is not parallel to the z-axis. The last thing you will need to do is to rotate the plane so that it's always perpendicular to the motion vector. All you have to do is apply your "pitches" and "yaws" to the whole plane (which represents the cross-section of your tunnel) instead of just the center point (representing the path of travel). Bonus: you can apply "rolls", too, just by adding an offset to your angle k which you smoothly vary. In fact it will just be that the tunnel wall is twisted, but from the inside I bet it'll be indistinguishable from https://www.google.com/search?q=do+a+barrel+roll".

    You might want to be careful about how you represent your rotations and apply them to your plane, however: look at the "gimbal lock" article (and the "see also" section for a good alternative) on Wikipedia.

    Or it could be that for a demo, gimbal lock won't be apparent at all.
    Last edited by a moderator: Apr 26, 2017
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Geometry: problem with defining the vertices of a tunnel around a given path
  1. Geometry problem (Replies: 1)

  2. Eulerian Path problem (Replies: 4)

  3. Geometry Problem (Replies: 1)

  4. A geometry problem (Replies: 2)