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

  • Thread starter cubud
  • Start date
  • Tags
    Screen
In summary, the conversation discusses using basic physics to achieve a desired movement for an object on a screen. The goal is to move the object a fixed distance in a fixed time, while slowing down at a constant rate. The conversation includes equations and calculations to determine the necessary initial velocity and acceleration for this movement.
  • #1
cubud
29
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
  • #2


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.
 
  • #3


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
 
  • #4


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:
  • #5


I will give this a try, thank you!
 
  • #6


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;
 

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

How can I calculate the velocity needed to move an object a fixed distance in a fixed time?

To calculate velocity, divide the distance by the time. For example, if you want to move an object 10 meters in 5 seconds, the velocity would be 10 meters / 5 seconds = 2 meters per second.

Can I use a formula to determine the acceleration required to move an object a specific distance in a specific time?

Yes, you can use the formula a = (vf - vi) / t, where a is acceleration, vf is final velocity, vi is initial velocity, and t is time. Rearranging the formula, you can solve for acceleration by multiplying the distance by 2 and dividing by the square of the time.

What is the relationship between speed and distance when moving an object in a fixed time?

The relationship between speed and distance is directly proportional. This means that as the speed increases, the distance covered in a fixed time also increases. Similarly, if the speed decreases, the distance covered decreases as well.

How can I ensure that an object moves the exact distance I want in the specified time?

To ensure that an object moves the exact distance in the specified time, you can use precise measurements and calculations. Additionally, you can use tools such as timers and motion sensors to accurately track the time and distance.

Is it possible to move an object a fixed distance in a fixed time without any external forces?

No, it is not possible to move an object a fixed distance in a fixed time without any external forces. According to Newton's first law of motion, an object at rest will remain at rest unless acted upon by an external force. Therefore, some external force is needed to move an object a fixed distance in a fixed time.

Similar threads

Replies
39
Views
3K
Replies
1
Views
1K
Replies
10
Views
1K
Replies
3
Views
2K
Replies
17
Views
3K
Back
Top