I am currently writing second version of the Flow Slider plugin and one of the animation options is when the slider accelerates at some constant acceleration up to some maximum speed and then decelerates with constant deceleration. I have a problem of finding the right timing for starting the deceleration.
If the time was continuous, there would be no problem, but time moves at discrete intervals and as a result there are some frames when movement is accelerating and (using continuous time math) you don't need to start decelerating, but in the next frame you are already too late to decelerate.
For example, lets say we have a frame rate of 20 per second. We need to move 500px, starting speed is 0px/frame, maximum speed is 50px/frame, acceleration is 3px/frame, deceleration is 3px/frame. Below you can see first 13 frames of the system.
| frame | speed | traveled | to go | deceleration distance |
|-----------------------------------------------------------
| 1 | 3 | 3 | 497 | 3 |
| 2 | 6 | 9 | 491 | 9 |
| 3 | 9 | 18 | 482 | 18 |
| 4 | 12 | 30 | 470 | 30 |
| 5 | 15 | 45 | 455 | 45 |
| 6 | 18 | 63 | 437 | 63 |
| 7 | 21 | 84 | 416 | 84 |
| 8 | 24 | 108 | 392 | 108 |
| 9 | 27 | 135 | 365 | 135 |
| 10 | 30 | 165 | 335 | 165 |
| 11 | 33 | 198 | 302 | 198 |
| 12 | 36 | 234 | 266 | 234 |
| 13 | 39 | 273 | 227 | 273 |
|-----------------------------------------------------------
Now, you can see that at 0.6s (12th frame) it is too early to decelerate, because deceleration distance of 234 is less than distance to go of 266. But already in the next frame (13th) the deceleration distance is much greater than the distance to go, and if we start to decelerate from there we won't finish on time.
What would be the best strategy to solve this?
You can try to adjust deceleration speed in the frame where 'its too late', so it will fit in smaller distance.