Linear Accelerated Motion
Exp7-Intro.jpg

Realistically modeling the motion of accelerating objects in a game is critical to having your players believe in the world you’re creating for them. This is what makes the Gran Turismo series such a success, accurate physics.
(Photo is from the game Gran Turismo 4)

Learning Objectives

  • Describe the quantities of position, velocity, acceleration, and time, and their relation to each other.
  • Recognize and utilize the correct units for position, velocity, acceleration, and time.
  • Implement the Forward Euler Method of integration to model motion.
  • Recall the advantages and disadvantages of the Forward Euler Method.

Introduction

One of the fundamental principles in any game is the motion of characters, ships, projectiles, and obstacles on the screen. Many of these motions can be very complex and dependent upon many different parameters. In this lab, we will investigate the simple motion of objects moving in a straight line subject to one acceleration function.

The velocity of a particle is the time rate of change in its position,

(1)
\begin{align} v = {{ \Delta x } \over { \Delta t }} \end{align}

The acceleration of a particle is the time rate of change in its velocity,

(2)
\begin{align} a = {{ \Delta v } \over { \Delta t }} \end{align}

Therefore, if the acceleration as a function of time is known, then the velocity and position of a particle can be determined for any time, t, since the previous two equations can be rewritten as follows:

(3)
\begin{align} \Delta x = { v \Delta t} \end{align}
(4)
\begin{align} \Delta v = { a \Delta t} \end{align}

These relationships are good over very short amounts of time when the change in the position or velocity are not extreme. The size of the time-step is critical to the stability of your results. If the time-step is too large, then the computed results will rapidly diverge from the true motion of the particle, and if the time-step is too small, your code will run too slowly and not be able to keep up with the pace of the game.

If the acceleration is uniform, then matters are much simpler. The position and velocity for a particle can be determined very quickly through analytic means rather than through numeric integration as above. Equations 1 and 2 can be manipulated to yield the following four equations that describe linear motion under uniform acceleration:

(5)
\begin{align} \Delta x = { v_i t + \left( 1/2 \right) a t^2 } \end{align}
(6)
\begin{align} \Delta x = { 1/2 \left( v_f + v_i \right) t } \end{align}
(7)
\begin{equation} v_f = { v_i + a t } \end{equation}
(8)
\begin{align} v_{f}^2 = v_{i}^2 + 2 a \Delta x \end{align}

In most instances, the initial velocity and accelerations will be known, so the first and third equations will be the most commonly used. Do keep in mind that these four equations are good ONLY if the acceleration is constant.
A very common case of constant accelerated motion is the motion of a falling body. Galileo had deduced, and supposedly demonstrated at the Leaning Tower of Pisa, that all objects fall with the same acceleration regardless of their mass. That acceleration is used so often in physics that it’s given its own symbol, g, where $g=9.8 m/s^2$. Equations 5 through 8, then, become very useful for accurately determining the position and speed of an object as it moves under the influence of gravity.

The Forward Euler Method is a method for evaluating the position and velocity of an object without having to evaluate equations 5 and 7 at every time step. The advantages are that it is quick to execute, easy to code, and easy to apply to non-uniform acceleration. Its biggest disadvantage is that it’s unstable and does not converge well. To determine the position of a particle first evaluate the new position by applying equation 3 in the following manner:

(9)
\begin{align} x_{new} = x_{old}+ v_{old} \Delta t \end{align}

The new velocity is found in similar fashion,

(10)
\begin{align} v_{new} = v_{old} + a_{old} \Delta t \end{align}

Notice in equation 10 that the acceleration also has a subscript, $a_{old}$. This allows for a non-uniform acceleration such as you would have when taking wind resistance into consideration. Equations 5-8 cannot handle a changing acceleration.

The source of the troubles with Forward Euler lies in its usage of the velocity at the beginning of the time-step as an approximation for the velocity throughout the time-step. The velocity is, of course, changing throughout the interval. The overall result is that the Forward-Euler method tends to add energy to a modeled system. Projectiles will go farther than they should, and oscillations will tend to grow over time. One way to combat this is to reduce the size of the time-step. Reducing the time-step size will have the adverse effect of slowing down your code’s execution, but it will improve the precision of your model. As a game programmer, one needs to find a good balance between speed and precision. Fortunately, a game environment doesn’t need to be as precise as a simulation. Forward Euler works well enough to make simple accelerated motion realistic and believable.

A more accurate, but more computationally expensive method is Velocity Verlet. There are major differences between Velocity Verlet and Forward Euler. First, the acceleration and velocity from the previous frame are both used to determine the position. Second, the new velocity is determined by using the average of the previous and current frame's accelerations.

(11)
\begin{align} x_{new} = x_{old} + v_{old} \Delta t + (1/2) a_{old} \Delta t^{2} \end{align}

Use the new position and old velocity to determine the new value of the acceleration.

(12)
\begin{align} v_{new} = v_{old} + \left( \frac { a_{old} + a_{new}}{2} \right) \Delta t \end{align}

The Velocity Verlet method is more computationally costly, but it is far more stable than the Forward Euler Method. After this project, the Velocity Verlet method will be our default method for integrating motion.

Laboratory Procedures

  1. Create a program that uses the Forward Euler method to model a ball being thrown upward from an initial height of 2.00 meters at an initial upward velocity of 49.0 m/s for times between 0.00 s and 10.00 s using a time-step of 0.10 s. Assume the acceleration to be due to gravity, -9.8 m/s2.
  2. Have your code output the time, position, and velocity data for the ball to the screen and to a comma-delimited ASCII file called “ex02_euler_0-10.csv”.
  3. Repeat this for time-steps of 1.0 s, and 0.01 s, outputting the data to files called “ex02_euler_1-0.csv” and “ex02_euler_0-01.csv”.
  4. Create a program that determines the position and velocity for the ball specified in Procedure 1 using the Velocity Verlet method, Equations 11 and 12. Output the data to a file called “ex02_verlet.csv”.
  5. Import the four data files into Excel or similar spreadsheet program and create a plot of position vs. time with all four datasets being plotted on the same graph.
  6. Create a program that determines the position and velocity for the ball specified in Procedure 1 using the Velocity Verlet method, but instead of assuming the acceleration to be a constant -9.8 m/s2, use the relationship, $a = - 9.8 - 0.10 v$, where a is in units of m/s2 and v is in units of m/s. This relationship will model the affect of air resistance on the ball. Output the time and position to a file named “ex02_wind.csv” and plot the data using a spreadsheet.
  7. Demonstrate the execution of your code and the graphical results to your instructor.

Postlab Questions and Exercises

  1. Were there any noticeable differences in the run-times when using a different time-steps? If so, why would this ever be an issue?
  2. When comparing the results of the Forward Euler calculations to the Velocity Verlet calculations, which time-step did best? Which did the worst?
  3. Is there any reason why you would ever select a time-step that you give you anything less than the best fit to an analytic solution?
  4. Wind resistance is a force that causes an object in motion to slow down over time much like friction. Wind resistance, however, produces an acceleration that is proportional to the velocity rather than a constant acceleration. The faster an object is going, the stronger the force of wind resistance is. Explain the benefits of using Forward Euler to model motion under the influence of wind resistance as opposed to solving for an analytic solution.
  5. Where else, other than a ball moving through the air, might you employ a wind resistance-like behavior?
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License