Updating the Position of an Object

Average and Instantaneous Velocity

From our study of physics we know that an object whose position is given by the vector \(\overrightarrow{r}\) has an average velocity during a time interval \(\Delta t\) (spanning times \(t_1\) to \(t_2\)) given by the displacement per unit time or

$$\overrightarrow{v}_{\textrm{av}} = \frac{\Delta \overrightarrow{r}}{\Delta t} = \frac{\overrightarrow{r_\textrm{f}} – \overrightarrow{r_\textrm{i}}}{t_\textrm{f} – t_\textrm{i}}$$

The velocity at a particular instant of time, or the instantaneous velocity, is found by letting the time interval \(\Delta t\) become very small

$$\overrightarrow{v} = \lim_{\Delta t\to\ 0} \frac{\Delta \overrightarrow{r}}{\Delta t}$$

which is also the derivative of the position with respect to time or

$$\overrightarrow{v} = \frac{\textrm{d}\overrightarrow{r}}{\textrm{d}t}$$

When we are modelling the motion of an object we cannot calculate the true instantaneous velocity because we can’t let the time step size approach zero.  What we can do is use a small enough time increment so that we can safely assume that the velocity has a constant value that is equal to the average velocity over that time interval.

In that case we can rewrite the average velocity formula as

$$\overrightarrow{r_\textrm{f}} – \overrightarrow{r_\textrm{i}} = \overrightarrow{v} \Delta t$$

or, rearranged in what we call the position update form, we have

$$\overrightarrow{r_\textrm{f}} = \overrightarrow{r_\textrm{i}} + \overrightarrow{v} \Delta t$$

If we have an object named ball then we can use the above expression to find its new position after a time dt has elapsed using

    ball.pos = ball.pos + ball.v * dt

In many cases we will update the momentum ball.p of the object instead of its velocity.  In such cases we find the velocity by dividing by the momentum by the mass as in

    ball.pos = ball.pos + (ball.p / ball.m) * dt