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!

I want to move an object on the screen a fixed distance in a fixed tim

  1. Sep 16, 2012 #1
    Hi everyone.

    I am a programmer and I think some basic physics will help me to achieve something I wanted to do.

    I want to move an object on the screen a fixed distance in a fixed time, but rather than moving with a uniformed velocity I want it to slow down at a constant rate so that it runs to a smooth stop.

    So if for example I wanted to move 64m over 2s, how would I work out what my initial velocity and acceleration should be?

    I appreciate any help. In fact I don't actually need to do this any more, but because I didn't know how to achieve the requirement I now have a strong urge to know how it should be solved.
  2. jcsd
  3. Sep 16, 2012 #2


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    Re: Acceleration

    So you want it to start from rest (u=0) accelerate for a while then decelerate to a stop 64m away from the start in time (T=2 seconds).

    Ok lets assume the rate of acceleration and deceleration are the same. In that case the problem can be split in two parts.

    1) Acceleration phase...

    It has to cover the first 32m in 1s. The relevant equation would be

    s = ut + 0.5 at2

    s = the displacement
    u = initial velocity = 0
    a = acceleration
    t = time

    Since u=0 it simplifies to

    s= 0.5 at2


    a = 2s/t2
    = 2*32/12
    = 64m/s2

    2) The deceleration phase is identical except "a" will need to be negative.
  4. Sep 17, 2012 #3
    Re: Acceleration

    Let me see if I can clarify. At an acceleration rate of 1pixel/second^2 I would expect my object to have the following Y locations over 6 seconds.


    What I need to do is the opposite. I wanted to understand an equation that when given the acceleration rate (-1 pixels/s^2), distance to travel (21pixels), and the total time over which to travel (6s) I end up with the initial velocity - resulting in the following

    Distance = 21pixels
    Time = 6 seconds
    Acceleration -1pixels/second^2
    = Initial velocity of 6 pixels/second

    Which would give me the following positions.
  5. Sep 17, 2012 #4


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    Re: Acceleration

    In which case you need...

    s = ut + 0.5 at2

    rearranged to give u the initial velocity..

    ut= s - 0.5at2

    u = s/t - 0.5at


    gives u = 6.5 pixels/second
    Last edited: Sep 17, 2012
  6. Sep 18, 2012 #5
    Re: Acceleration

    I will give this a try, thank you!
  7. Oct 31, 2012 #6
    Re: Acceleration

    Worked great, I thought I'd share the source in case anyone else stumbles across this. It should be pretty easy to work out the calculations from it.

    Code (Text):
    function TSpriteBehaviorMoveTo.GetFullyEasedOffset(
      Original: Single;
      Target: Single;
      DurationSecs: Single;
      TotalDeltaTime: Single
    ): Single;
      HalfDistance: Single;
      HalfTime: Single;
      Acceleration: Single;
      CurrentTime: Single;
      HalfTime := DurationSecs / 2;
      HalfDistance := (Target - Original) / 2;
      Acceleration := HalfDistance / ((HalfTime * HalfTime) * 0.5);

      if (TotalDeltaTime <= HalfTime) then
        CurrentTime:= TotalDeltaTime;
        Result := Original + (0.5 * acceleration * CurrentTime * CurrentTime);
      end else
        CurrentTime:= DurationSecs - TotalDeltaTime;
        Result := Target - (0.5 * acceleration * CurrentTime * CurrentTime);
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook