Velocity curve help?

Started by
4 comments, last by j0n3z 23 years, 7 months ago
Hello all. I am trying to control the speed of an object along a parametric spline (cardinal spline). I have been trying to create a velocity curve using values of speed specified at the control points, but without success. If anyone has any experience with velocity curves then I would appreciate some tips. Thanks in advance. Jon Edited by - j0n3z on 9/2/00 3:28:36 PM
Advertisement
I am not sure what you are meaning here, but I''ll just use my old Physics knowledge to suggest some ideas.

If you want to make something move along a curve you have to use speed VECTORS.
For instance, take a nice inverted U shaped curve. The initial velocity is (cos(90),sin(90)) (pointing up), then at the aspex (is that the word in english ?) of the curve you would have a vector pointing right (cos(0),sin(0)), then finally your last vector would be (cos(-90),sin(-90)).
If you interpolate the vector from one point to another, you will get a perfect circle, or an ellipse, depending on your interpolation method.
This doesn''t take gravity into account of course. It would be to make something more like a rail track...

Or maybe you could explain better what you want ?

youpla :-P
-----------------------------Sancte Isidore ora pro nobis !

I am using a parametric curve, which all works fine. This function, lets call it ''p(u)'' takes a parameter u such that u represents the fraction travelled along the curve. Therefore,

p(0) = Starting point of interpolation.
p(0.5) = Half way along interpolation.
p(1) = End point of interpolation.

This isn''t the problem however, as this works fine. If I change the value of u linearly with time, then I interpolate linearly and any objects on the spline move linearly.

Altering the speed of the object on the spline is not so simple. Instead of using a linear relationship between time and the value u, it is possible to construct a velocity curve. A velocity curve maps values of time to values of u non-linearly. It can easily be seen that the gradient of the velocity curve is what controls the speed of the object.

But this is all the information I know. What I need is some suggestions or a web address or something.

I know it''s not a straight forward problem, but I was hoping someone may have used them before.

Thanks for any help.

Jon.
Like you said, this _is_ a tricky problem; it''s actually complicated by the fact that one of the things you said is a little incorrect. Normally velocity (or speed, more accurately) isn''t constant along the spline curve: that is, if you move t in linear fashion from 0 to 1 your distance along the spline _won''t_ increase linearly and the user''s perception may be a speeding-up and slowing-down of the interpolated object (or camera, or whatever). Correcting this is actually the hardest part of the problem; if you feel your interpolation speed is close enough to constant to begin with, then correcting it to the speed you want is easy.

The basic notion (to correct from linear to nonlinear speed) is that you perform a second interpolation that maps the time the user provides into ''parametric'' time -- the value that you plug into the parametric equations. Odds are good that C^1 (piecewise-linear) interpolation of speed will be good enough; that is, speed should be continuous but accelleration doesn''t have to be.

Given this, the derivation is easy. Let''s say you''ve arranged things so that the ''natural'' speed along your spline is exactly 1 (m/s, or whatever); that is, it travels one unit of distance as u (I''m using u as the parameter governing the equation) goes from 0 to 1. Then the speed of the object itself is dx/dt -- the derivative of position with respect to time. By the chain rule, this is equal to dx/du * du/dt. dx/du is 1 (the condition above), so the speed of the object boils down to du/dt. What you''re saying is that you want the user to be able to set the speed of the object at the two endpoints -- we''ll call these speeds s0 and s1 -- and figure out (a) how long it should take to get from point u=0 to point u=1, and (b) how to figure out u from t during that whole time frame.

Crank the math: du/dt (at the u=0 point) is s0 and du/dt (at the u=1) point is s1. Assume the speed linearly interpolates between them; then du/dt = s0+(s1-s0)*t = s0+s01*t (introducing a new variable s01 = s1-s0). Since we can parameterize one endpoint arbitrarily we may as well set t=0 when u=0; then the solution to this equation is u=s0*t+(1/2)*s01*t^2. Now we need to figure out how far t goes before we get to u=1; in other words, how long in ''real'' time (given the speeds we set) it takes to traverse from u=0 to u=1. This just says that s0*t+(1/2)*s01*t^2 = 1, or (1/2)*s01*t^2+s0*t-1 = 0. Use the quadratic formula and you''ll get t=(-s0) +/- sqrt(s0^2+2s01) -- since we want t to be positive you''ll want the + sign here, giving t = sqrt(s0^2+2s01) - s0.

So once you''ve got all this, you''d work things this way:
(1) compute t as a function of frame number (t = frno/60 or something). Note that I''ve left open the issue of shifting t to go from curve to curve, but that should be easy to figure out.

(2) compute u as a function of t by the equation above; u = s0*t+(1/2)*s01*t^2.

(3) compute your position as a function of u, using your normal spline formula.

If you want to correct for the (hopefully) slight nonlinearity in travel speed that almost any cubic spline curve has then things get even trickier, with your best bet probably being a lookup table approach; I can get into that in more detail if you''d like but this post is long enough already. :-)
Helluva post from an initiate. Hope you stick around, Shaterri.

Shaterri,

Thanks very much for your impressive looking responce! I''m gonna get the trusty pen & paper out and try and follow your maths.

Thanks again.

Jon.

This topic is closed to new replies.

Advertisement