0

When calling the derivative method on the CatmullRomSpline, what exactly does this value represent? It’s been a while since calculus, but if my memory serves me correctly taking the derivative of the position with respect to time gives you the velocity at that point in time. But with CatmullRomSpline the “time” value is a percentage, so is the resulting derivative in pixels/percent?

I printed out the derivative values (vector length) along my path and the values go as high as “989.6049”, which doesn’t really make sense to me as the total length of the path is 2039 (calculated using the “approxLength(1000)” method). I’ve tried a few things to get the derivative values into a range that makes sense (like dividing by total path length) but I’m still not making sense of it.

Essentially, I’m trying to figure out how to get a constant velocity along the path. My plan is to use the derivatives to get the rate at a given instant and compare that to what the rate should be if it was constant (calculated from the length of the path) and then adjust the percent value that is fed into the CatmullRomSpline valueAt() method so that the resulting speed will be constant throughout the path. Thanks.

Tekkerue
  • 1,497
  • 1
  • 11
  • 17
  • They explain it well in [Path Interface and Splines](https://github.com/libgdx/libgdx/wiki/Path-interface-&-Splines) under "Make the sprite traverse at constant speed" – Johnathon Havens Sep 18 '15 at 03:40
  • Thanks Johnathon. I have read the wiki but it doesn’t go into what the derivative means. The sample code also doesn’t make sense and I wasn’t able to get it to work. In my case the derivative values were very large and dividing a number ranging between 0-1 by a number in the hundreds (989 was my max derivative value) resulted in a tiny number so the movement was incredibly slow but still not constant. I don’t see how their example works. While my original question was on the derivative function if it would be easier to help with constant speed I could start a new question on that instead. – Tekkerue Sep 18 '15 at 06:10
  • That sounds interesting, do you have some code examples that produce your results? The more the merrier. – Johnathon Havens Sep 18 '15 at 18:44
  • Johnathon, I started a new question focusing on achieving constant speed and I included some sample code. If you'd like to take a look at it, here is the link. Thanks! http://stackoverflow.com/questions/32665262/libgdx-path-catmullromspline-constant-speed – Tekkerue Sep 19 '15 at 07:00

0 Answers0