View Full Version : tangent of a spline at any point

mcsellski

04-25-2002, 04:18 AM

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 = ((2*t*t*t)-(3*t*t)+1) * startX

+ ((-2*t*t*t)+(3*t*t)) * enX

+ ((t*t*t)-(2*t*t)+t) * tangent1X

+ ((t*t*t)-(t*t)) * tangent2X;

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

+ ((-2*t*t*t)+(3*t*t)) * endY

+ ((t*t*t)-(2*t*t)+t) * tangent1Y

+ ((t*t*t)-(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

nutball

04-25-2002, 05:12 AM

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'.

nickels

04-25-2002, 07:31 AM

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).]

mcsellski

04-25-2002, 10:21 PM

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

Devulon

04-26-2002, 01:39 AM

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 (http://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.

mcsellski

04-29-2002, 11:21 PM

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

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.