1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Calculating speed and reversing inertia

  1. Jun 27, 2011 #1

    I'm a programmer and while my maths is OK, my understanding of physics is not the best so apologies in advance if I'm missing something obvious. My problem is an interaction and animation sequence I'm writing, the user can swipe an object from one position to another. No problem here. The issue is that I need the object to 'dock' to a specific position, again no problem calculating the final resting position.

    My problem is that I applying inertia (I decrement the detected speed on each animation cycle so this value is undeterminent) causing the object to slow and then stop once it hits a specific figure. Originally I thought I could calculate the 'expected distance' the object would travel to, but I believe that I did not have enough parameters to do this, only the speed and deceleration value. To calculate the expected distance, I create a second loop, decrement the speed but adding to the expected distance until it hits the stop speed. Not overly elegant, but it returns the correct figure.

    However, to get the object to end at a specific position I need to reverse this calculation, adjusting the speed of the object so it lands in the appropriate position. At the moment, I've been using Vf^2 = Vi^2 + 2ad but this hasn't been providing the correct values so far.

    For instance, the speed is 38 pixels per animation frame, the initial starting velocity is 0.05 pixels per animation frame and we expect to move 721.0825 pixels in total. After the positioning calculation (which is fine), the expected distance is revised to 785. Note: during the animation, the speed is decremented by 95% on each animation frame so I'm setting the acceleration to 1.05225 (as an arbitary figure).

    So if I done things correctly, the speed should be square root of ( ( 2 * 785 * 1.05225 ) + ( 0.05 ^ 2 ) ), which equals 40.65542.

    But as you've guessed it, this isn't working and is providing very wonky results? Have I missed something out? Am I using the wrong formula as the speed is not constant (as it is decremented on each animation until the speed reaches 0.05)?

    Any help, (of any kind) is gratefully received.


    Note: I do have a workaround by adjusting the speed using a percentage, e.g. (revised distance / expected distance) * speed that works but isn't pixel perfect. But I'm sure there's a more elegant approach.
  2. jcsd
  3. Jun 27, 2011 #2
    hello there. The equations of motion you have used are for frames that have linear acceleration. However when you are deducing the decrement in speed (the effecting acceleration) you calculate the acceleration based on a percentage of the speed of the object. this means the acceleration (total speed decrement) at some point p is going to be smaller than the acceleration at some later point q because the speed at q is lower. try making the acceleration a parameter thatll be an absolute constant i.e. change the speed decrement to a non percentage value like 5 or 10. or you could change ur motion calculation formulae to take into account a non linear acceleration. for example: if you let y be the y cordinate of your object then at some later time t
    y = y_0 + vt + (1/2 * a * t^2)
    where a == speed decrement * v
    or equivalently, the formulae you used in ur program
    Vf^2 = Vi^2 + 2ad
    but now a = speed decrement * v
    mind you this may cause some uncertainty because we are using a linear formulae for a nonlinear acceleration
  4. Jun 27, 2011 #3
    and by that i mean error
  5. Jun 28, 2011 #4
    Unfortunately I need the animation to feel like a natural action (i.e. fiction stops the object from moving). In addition, the speed may very well differ meaning that a higher speed will take much, much longer to stop with a constant speed as opposed to a decrementing value.

    Thanks for your input though, I'll have to see how well the percentage adjustment works in the wild.

    However, if there is a true way of calculating with the anticipated speed I would dearly love to hear it :)
  6. Jul 22, 2011 #5
    after a very large delay, and having fun with my ban... the answer to your question was in my original post. the value a should take (aceleration) isnt simply the decrementing coefficient but the decrementing coefficient times the velocity of the particle at that time.
    for the non linear formulae of motion, all i can do is refer you to any classical mechanics or dynamics books. you should find examples answered also in calculus books.
  7. Jul 22, 2011 #6
    im going to demonstrate with an example:
    say you adjust the parameters so that the particle leaves with initial velocity u. you adjust the acceleration coefficient so that at some well defined time interval dt, the velocity is decremented by some coefficient c of its initial value, hence the value of acceleration (change in velocity) is equal to: a=v.c
    the velocity of the particle the final point (vfin) then is given by vfin = u + a.dt
    here I have missed out an integral sign behind a.dt as I am not sure how to draw one.
    in essense then, if you set your program to decrement values from the velocity at some well defined time interval dt, and record the velocity at each point, you then know the acceleration at each point, letting you calculate the final velocity. to find the stopping distance then you take the integral of the vfin function.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook