Calculate the position of an accelerating body after a certain time

Iain picture Iain · Sep 30, 2008 · Viewed 48.2k times · Source

How do I calculate the position of an accelerating body (e.g. a car) after a certain time (e.g. 1 second)?

For a moving body that it not accelerating, it is a linear relationship, so I presume for an accelerating body it involves a square somewhere.

Any ideas?

Answer

Chris Johnson picture Chris Johnson · Sep 30, 2008

The equation is: s = ut + (1/2)a t^2

where s is position, u is velocity at t=0, t is time and a is a constant acceleration.

For example, if a car starts off stationary, and accelerates for two seconds with an acceleration of 3m/s^2, it moves (1/2) * 3 * 2^2 = 6m

This equation comes from integrating analytically the equations stating that velocity is the rate-of-change of position, and acceleration is the rate-of-change of velocity.

Usually in a game-programming situation, one would use a slightly different formulation: at every frame, the variables for velocity and position are integrated not analytically, but numerically:

s = s + u * dt;
u = u + a * dt;

where dt is the length of a frame (measured using a timer: 1/60th second or so). This method has the advantage that the acceleration can vary in time.

Edit A couple of people have noted that the Euler method of numerical integration (as shown here), though the simplest to demonstrate with, has fairly poor accuracy. See Velocity Verlet (often used in games), and 4th order Runge Kutta (a 'standard' method for scientific applications) for improved algorithms.