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

  • Thread starter Thread starter cubud
  • Start date Start date
  • Tags Tags
    Screen
Click For Summary
A programmer seeks to move an object a fixed distance with a smooth stop, requiring an initial velocity and acceleration calculation. The movement is divided into two phases: acceleration and deceleration, each covering half the distance in half the time. Using the equation s = ut + 0.5at², the initial velocity can be derived as u = s/t - 0.5at. For a distance of 21 pixels over 6 seconds with a deceleration of -1 pixel/second², the initial velocity is calculated to be 6.5 pixels/second. The programmer shares a function to implement this easing behavior effectively.
cubud
Messages
29
Reaction score
0
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.
 
Physics news on Phys.org


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 let's 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

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

Since u=0 it simplifies to

s= 0.5 at2

or

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

2) The deceleration phase is identical except "a" will need to be negative.
 


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.

0,1,3,6,10,15,21

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.
21,15,10,6,3,1,0
 


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

Edit:

gives u = 6.5 pixels/second
 
Last edited:


I will give this a try, thank you!
 


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:
function TSpriteBehaviorMoveTo.GetFullyEasedOffset(
  Original: Single;
  Target: Single;
  DurationSecs: Single;
  TotalDeltaTime: Single
): Single;
var
  HalfDistance: Single;
  HalfTime: Single;
  Acceleration: Single;
  CurrentTime: Single;
begin
  HalfTime := DurationSecs / 2;
  HalfDistance := (Target - Original) / 2;
  Acceleration := HalfDistance / ((HalfTime * HalfTime) * 0.5);

  if (TotalDeltaTime <= HalfTime) then
  begin
    CurrentTime:= TotalDeltaTime;
    Result := Original + (0.5 * acceleration * CurrentTime * CurrentTime);
  end else
  begin
    CurrentTime:= DurationSecs - TotalDeltaTime;
    Result := Target - (0.5 * acceleration * CurrentTime * CurrentTime);
  end;
end;
 
Thread 'What is the pressure of trapped air inside this tube?'
As you can see from the picture, i have an uneven U-shaped tube, sealed at the short end. I fill the tube with water and i seal it. So the short side is filled with water and the long side ends up containg water and trapped air. Now the tube is sealed on both sides and i turn it in such a way that the traped air moves at the short side. Are my claims about pressure in senarios A & B correct? What is the pressure for all points in senario C? (My question is basically coming from watching...

Similar threads

  • · Replies 9 ·
Replies
9
Views
1K
Replies
6
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 39 ·
2
Replies
39
Views
5K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 22 ·
Replies
22
Views
2K