tangent of a spline at any point

Hi, can anyone tell me how to work out the tangent of a spline at any point along it’s length. I realise that I can fit a line though points, get the equation of the polynomial and differentiate however, I have been using the following method for finding my spline vertices and was wondering if there as an easy way…

x = ((2ttt)-(3t*t)+1) * startX

  • ((-2ttt)+(3t*t)) * enX
  • ((ttt)-(2tt)+t) * tangent1X
  • ((ttt)-(t*t)) * tangent2X;

y = ((2ttt)-(3t*t)+1) * startY

  • ((-2ttt)+(3t*t)) * endY
  • ((ttt)-(2tt)+t) * tangent1Y
  • ((ttt)-(t*t)) * tangent2Y;

I borrowed this from somewhere in the GL examples, does anyone recognise it? What is bothering me is that the length of the tangents at the end points appears to put some tension in the spline itself, so that’s what has me wondering if there is a related way for determining the tangent of the spline and any intermediate point.

Any help appreciated.

Thanks

Matthew

Originally posted by mcsellski:
Hi, can anyone tell me how to work out the tangent of a spline at any point along it’s length. I realise that I can fit a line though points, get the equation of the polynomial and differentiate however, I have been using the following method for finding my spline vertices and was wondering if there as an easy way…

Differentiate the above equations with respect to ‘t’.

the pair (tangent1x, tangent1y) is the direction the curve starts on one end, the pair (tangent2x, tangent2y) are the direction the spline starts from the other end.

Notice that at t=0 you get (startX, startY) and at t=1 you get (endX,endY).

Also notice x’[0] = Tangent1X, x’[1] = tangent2X, y’[0] = tangent1y, y’[1] = tangent2y (just differentiate with respect to t and evaluate]. Thus in the xy plane the tangent vector is (x’[0],y’[0]) at one end and (x’[1],y’[1]) at the other.

here, x’[t] means derivative of x[t] (of course).

This spline only connects two points, so to connect more you would have to apply this to a series of point pairs. The tangent vectors then become knobs that you can use to tweak the shape of your curve (the must agree between adjacent curves at the shared point) or your curve will be continuous but not smooth.

[This message has been edited by nickels (edited 04-25-2002).]

Thanks guys for your help. I had no idea where the equations were derived from so I didn’t know what I’d get if I differentiated wrt t.

I’ve been using the equation for drawing splines and using the tangents for controlling the shape by dragging points interactively. Now I want to be able to subdivide the spline that I have into multiple splines and to do that I need to know the tangent at the points I’m going to divide at.

You’ve helped me to figure out how to do that. Thanks again.

matthew

Looks like good old classic Bezier Splines to me. Yup all you gotta do is differentiate with respect to to and you now have tangents. Just like back in high school. I really don’t like to shamelessly promote my products but take a look at UltraCoaster at www.reactorsoftware.com

Its a project I worked on a while back with an old friend from college. Unfortunately its DirectX and you can’t have the source, but its built using bezier splines exactly like yours and fitting a crossection to the track. Basically a loft along a spline.

I really think you should grab the demo and check it out. It really shows off one of many cool things you can do with splines.

Very nice indeed. I seem to remember trying this demo some time ago. Actually, there is a feature in your software that I have wanted to use in mine, but it is currently beyond my ability. My application maps real-time temperature data to a skin, either in 2D or 3D. The app has two modes, runtime and design time. The former is merely passive and displays the temperature data mapped onto a model, the latter is the IDE used to create the model. Currently, I can map temperature onto cylidrical shapes including domes and cones, planes and cubes/rectangles etc. However, I cannot yet do convoluted pipework, something that your Ultra Coaster does very well.

Regards

Matthew