# 'Extruding' from a spline

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

## Recommended Posts

There was a recent thread that touched this, but it turned into a bit of an argument, so I thought I'd make a new one. I have a normal evaluatable (3d) spline, and I'm trying to extrude it outwards - turn it into a cylinder mesh in effect. I can work out the direction vector of the spline no problem, but I need another orthogonal vector. Once I've got this I can extrude one vertex along it, and then rotate it around the direction vector to generate the other points. There are two ways of doing this as far as I can see, so this is what I'd like to know: First method: I can get my vector by choosing a random vector, and then cross-producting, but then my extruded vertices will be placed in an unpredictable pattern. Is there any way of choosing this 'random' vector so that they are ordered in a predictable way? Second method: is there some constraint that I can place on the system to generate a useful orthogonal vector? I can't think of one...

##### Share on other sites
So what you need is just which direction to extrude? Well, you've just got to come up with a rule and stick with it, basicly. Like, always use +z direction. The only other real option is to have the user enter the direction in some manner.

One other idea: if your spline is always planar (or near planar) you can pick a few points along the length of the spline and do some vector subtracts and a cross product to get a direction for the extrusion that will give you something full of volume.

##### Share on other sites
the first derivative of the spline parametric equation should give you the direction at the point of interest. The second derivative should give you the 'acceleration', which can be compared to the centrifugal force, in a very broad sense. So that should give you the natural outward curvature of the spline, hence the extrusion you are probably looking for. Cross producting the direction and the acceleration vector should give you the normal of the 'road'.

Note that it's restricted to splines which are continuous at the second derivative (C2 continuous, as they are called, so not catmull-rom, for example).

for those, you have to artificially find the most suited curvature, like basically, do it by hand yourself (take two relatively close points direction, using the first derivative, since this one is continuous, cross product the two directions to get the normal at the point in the middle, and cross product the normal and the direction at the point to get the extrusion vector).

##### Share on other sites
Quote:
 Original post by wendigo23Well, you've just got to come up with a rule and stick with it, basicly. Like, always use +z direction..

Well, there needs to be a slight adjustment for when the direction is +z of course, but that shouldn't be hard. Thanks!

##### Share on other sites
How about starting with a random perpendicular vector at one end of the spline, then for each point you evaluate on the spline, adjust the old vector to make it perpendicular again. That way, it would change smoothly no matter how the spline might twist around, even if you linked a series of splines together.

##### Share on other sites
picking an arbitrary vector will either have the risk of them being parralel, or if you pick another vector when the are near-parralel, the outcome wont be continuous anymore. besides you wont have any control over the output with this method.

oliii is right. note that it will only work when there actually is a curvature though, otherwise your second derivative is zero, and youre still in trouble. maybe the best way would be to have the user specify the direction.

##### Share on other sites
Thanks for the help, guys.

##### Share on other sites
I was thinking about this. What you really have is a polyline and not a spline. The spline is just used to generate the polyline. So rather than using the actual normal and binormal you could just approximate them at the corners from the two adjacent line segements. If two segements happen to be colinear you could just merge them. At the start of the pipe you could just use the approximation at the next vertex.

##### Share on other sites
in case of no curvature, use the previously found normal, or slowly turn back into a flat section.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 10
• 9
• 15
• 22