Deceleration time

I am currently writing the second version of the Flow Slider plugin, and one of the animation options is when the slider accelerates with some constant acceleration to a certain maximum speed, and then slows down with a constant slowdown. I had a problem finding the right time to start the slowdown .

If time was continuous, there would be no problems, but time moves at discrete intervals, and as a result there are several frames when accelerating the movement and (using continuous time mathematics), you do not need to start slowing down, but in the next frame you slow down too late .

For example, let's say we have a frame rate of 20 per second. We need to move 500 pixels, the initial speed is 0 pixels / frame, the maximum speed is 50 pixels / frame, the acceleration is 3 pixels / frame, the slowdown is 3 pixels / frame. Below you can see the 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 it is too early to slow down by 0.6 s (the 12th frame), because the braking distance 234 is less than the distance to 266. But already in the next frame (13th), the braking distance is much larger than the distance to places, and if we start to slow down from there, we will not finish on time.

What would be the best strategy to solve this problem?

+4
source share
1 answer

You can try to adjust the braking speed in the frame where it is "too late", so it will be located at a shorter distance.

0
source

Source: https://habr.com/ru/post/1389843/


All Articles