Geometry: problem with defining the vertices of a tunnel around a given path
Posted 02 November 2011 - 08:21 PM
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)
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? :)
Posted 02 November 2011 - 10:03 PM
Posted 02 November 2011 - 10:28 PM
Also, how could I find the tangent vector of the path at a given point (especially when the path can turn both left/right and up/down at the same time), and what is a good way to align the ellipse to it?
Posted 02 November 2011 - 10:57 PM
If you actually want to do sharp bends in a path that's otherwise straight, like you showed in your diagram, then I'd probably generate a sector of a torus to fill in the bend.
In either case, to align the circle or torus with the path, you could use a look-at matrix, passing the tangent vector in as the look-at vector.
Posted 02 November 2011 - 11:46 PM
I'm not sure what you mean with generating a sector of a torus though?
Where I want to go with this, is more like the way that 3dsmax handles the problem.
Unfortunately it doesn't show me the formula they use :(
Edit: and thanks again! You just helped me a bunch :)
Posted 03 November 2011 - 12:34 AM
Posted 03 November 2011 - 02:47 AM
The best thing about Bezier paths is you can easily manipulate them. You can interpolate the radius along the path to produce interesting solids (like tree branches) and you easily move control points around to add different slopes, rotations, or to construct complex geometric shapes. The torus shape in my demo for example is nothing more than a looped path (6 control points in total).
If you have Blender 3D, you can see what 2D and 3D representations of Bezier paths look like, and even play around with it to get a good feeling of how it works.
Posted 03 November 2011 - 12:08 PM
Posted 03 November 2011 - 04:38 PM
When using splines, another possibility is to define a normal vector using the second derivative of the curve; see here for details. The trouble with this is it may be discontinuous from one spline segment to the next, and it will fail on a straight-line segment since the second derivative will be zero.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users