how to calculate a negative acceleration?

后端 未结 15 1758
既然无缘
既然无缘 2021-02-08 12:11

I\'m implementing the scrolling behaviour of a touch screen UI but I\'m too tired in the moment to wrap my mind around some supposedly trivial piece of math:

y (         


        
15条回答
  •  失恋的感觉
    2021-02-08 12:34

    While the car is slowing down I want to be able to calculate the velocity it will have exactly one second later solely based on it's current velocity.

    That would be the definition of acceleration. For instance, if the acceleration was a = -9 meters/sec/sec, and the velocity right now is 20 meters/sec, then 1 second from now the velocity will be 11 meters/sec.

    In otherwords, the change in velocity Δv between now and t seconds from now (assuming constant acceleration) would be

    Δv = a*t

    meaning that the (classic physics) equation for the velocity at any time t, given the initial velocity at t=0 (this velocity is called v0) is

    v(t) = v0+ a*t


    Using what you'll learn in the first two weeks of calculus class, you can also get the equation for x(t) (the distance of the car at time t) from the above equation; this would give you

    x(t) = x0+ v0*t + 0.5*a*t2

    (it is also possible to derive this without calculus, see here)


    Finally, if you are doing this for a game, and not a physics simulation (meaning you don't need exactly precise results), you will want to simply change the position and velocity every frame, rather than recalculate the position every frame. To do this, you will want to do the following every frame, assuming velocity (and acceleration) is measured in pixels-per-second(-per-second):

    velocity_new = velocity_old + acceleration/frames_per_second
    position_new = position_old + velocity_old/frames_per_second
    

提交回复
热议问题