Table of Contents

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)The acceleration of a particle is the time rate of change in its velocity,
(2)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)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 timestep is critical to the stability of your results. If the timestep is too large, then the computed results will rapidly diverge from the true motion of the particle, and if the timestep 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)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 nonuniform 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)The new velocity is found in similar fashion,
(10)Notice in equation 10 that the acceleration also has a subscript, $a_{old}$. This allows for a nonuniform acceleration such as you would have when taking wind resistance into consideration. Equations 58 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 timestep as an approximation for the velocity throughout the timestep. The velocity is, of course, changing throughout the interval. The overall result is that the ForwardEuler 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 timestep. Reducing the timestep 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.
Laboratory Procedures
 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 timestep of 0.10 s. Assume the acceleration to be due to gravity, 9.8 m/s^{2}.
 Have your code output the time, position, and velocity data for the ball to the screen and to a commadelimited ASCII file called “ex02_euler_010.csv”.
 Repeat this for timesteps of 1.0 s, and 0.01 s, outputting the data to files called “ex02_euler_10.csv” and “ex02_euler_001.csv”.
 Create a program that determines the position and velocity for the ball specified in Procedure 1 using Equations 5 and 7. Output the data to a file called “ex02_analytic.csv”.
 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.
 Create a program that determines the position and velocity for the ball specified in Procedure 1 using the Forward Euler method, but instead of assuming the acceleration to be a constant 9.8 m/s^{2}, use the relationship, $a =  9.8  0.10 v$, where a is in units of m/s^{2} 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.
 Demonstrate the execution of your code and the graphical results to your instructor.
Postlab Questions and Exercises
 Were there any noticeable differences in the runtimes when using a different timesteps? If so, why would this ever be an issue?
 When comparing the results of the Forward Euler calculations to the analytic calculations, which timestep did best? Which did the worst?
 Is there any reason why you would ever select a timestep that you give you anything less than the best fit to the analytic solution?
 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.
 Where else, other than a ball moving through the air, might you employ a wind resistancelike behavior?