Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animation with Initial Velocity

I've been trying to solve this problem for a number of days now but I must be missing something.

Known Variables:
vi = Initial Velocity
t = Animation Duration
d = Distance.
end velocity should always be zero

The function I'm trying to create: D(0...t) = the current distance for a given time

Using this information I want to be able to create a smooth animation curve with varying velocity (ease-in/ease-out).

The animation must be able ease-in from an initial velocity.

The animation must be exactly t seconds and must be travel exactly d units.

The curve should lean towards the average velocity with acceleration occurring at the beginning and the end portions of the curve.

I'm open to extra configuration variables.

The best I've been able to come up with is something that doesn't factor in the initial velocity. I'm hoping someone smarter can help me out. ;)

Thank you!

p.s. I'm working with an ECMAScript variant

like image 953
abustin Avatar asked Apr 01 '10 00:04

abustin


1 Answers

Here is a different solution, where there isn't any time interval where the velocity is constant. Instead, velocity as a function of time is a second-order polynomial, and the acceleration is linear in time (positive at the beginning, and negative at the end). Maybe you can try it.

Let me rename your variables a bit. Let

  • T = final time = animation duration
  • V = initial velocity (>0)
  • D = total distance (>0)

We are searching for a smooth function v(t) (velocity as a function of time) such that:

  • v(0) = V
  • v(T) = 0
  • the integral from 0 to T of v(t)dt is D

With a (concave) second-order polynomial we can satisfy all the three constraints. Hence, let

v(t) := at^2 + bt + c

and let's solve for a, b, c. The first constraint v(0) = V gives immediately c = V. The second constraint reads

aT^2 + bT + V = 0

On the other hand, the integral of v(t) is d(t) = 1/3 a t^3 + 1/2 b t^2 + Vt (this is the distance covered up to time t), hence the third constraint reads

d(T) = 1/3 a T^3 + 1/2 b T^2 + VT = D

The last two equations seem messy, but they are just two linear equations in the two unknowns a, b, and they should be easily solvable. If I did my computations correctly, the final result is

a = 3V/T^2 - 6D/T^3, b = 6D/T^2 - 4V/T

If you substitute a, b, c in the expression of d(t), you obtain the covered distance as a function of time.

like image 181
Federico A. Ramponi Avatar answered Sep 30 '22 13:09

Federico A. Ramponi