# constant speed moving on spline

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

## Recommended Posts

I am sure this is really really simple, but still.. I have a tcb spline which has keyframes with a time value between 0(start) and 1(end). I can get a point on the spline with spline.getData(t). Now, I have an object which I want to move along the spline with constant speed. however, since the the spatial distance between two points is not relative to the time-frame between them, it's not that easy to do. 0 0.5 1.0 a---b----------------------c illustrated here, with a,b,c as keys and -'s representing spatial distance. the number is the key's time. now my current solution is to calculate the entire(spatial) length of the spline, and then calculate the spatial length from key 0 to key n and set that key's time to thisLength/TotalLength; Is there an easier way? Also currently, I'm not sure if this method is working correctly either, but it seems kind of close. I'm currently calculating spline length by step-throughing at small intervals and adding up deltas. if anyone know an analytic way of doing it, please let me know. I tried to look at arc length on wikipedia, but I'm not sure how to integrate the expression.

##### Share on other sites
The general solution is to re-parameterize your curve using arc-length instead of time, giving you something like:

xi = f(g-1(s))

For any number of dimensions, where g(t) is arc-length as a function of time. However this usually isn't easy (or even possible) to do analytically, since g(t) can quickly become unmanageable. So you do it numerically, taking an approach similar to that in Dave Eberly's Moving Along a Curve with Specified Speed paper. You could also continue with what you're doing and add up a bunch of tiny linear segments, although it might not be very accurate once your curve starts to get too... "curvy".

##### Share on other sites
The most common way to solve this generally is to reparameterise the spline so that it is uniform. The term is arc-length parameterisation. Rather than trying to integrate a horrible analytic expression, you'd probably be best off doing things numerically. I haven't read it, but this article is often linked to.

Edit: Too slow. I guess this goes to show how much practice we've had at some of these questions [rolleyes].

• ### 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!

• 12
• 14
• 10
• 14
• 24