<< Chapter < Page Chapter >> Page >

A graphical representation of velocity

The velocity values shown in Figure 4 are plotted in Figure 1 along with the height values and the acceleration values, which will be computed shortly..

Analysis of the results

The difference between Figure 2 and Figure 4 is the addition of a column of velocity information on the right in Figure 4 . As you can see, the velocity begins with a positive value of 100 feet/second at the top of thevelocity column.

The velocity goes to zero somewhere between 3 and 3.25 seconds, which is the point where the height of the arrow reaches its maximum.

At 3.25 seconds, the velocity switches from positive to negative meaning that the arrow begins falling back toward the earth. The velocity reaches-100 feet/second somewhere between 6.25 and 6.5 seconds, which is about the same time that the arrow hits the ground.

Hopefully you have recognized that the velocity curve for this particular situation is a straight line with a negative slope. Thatstraight line crosses the horizontal axis going from positive territory into negative territory about half way between the original release of the arrow andthe point where the arrow strikes the ground.

Analysis of the code

A comparison of Listing 2 with Listing 1 shows the addition of the following variables:

  • var oldT = 0; //previous time in seconds
  • var delT = 0; //change in time in seconds
  • var oldH = h0; //previous height in feet
  • var delH = 0; //change in height in feet

Save values for use in next iteration

As you will see when I get into an explanation of the while loop, the variables oldT and oldH are used to save the time value and the height value during each iterationto make those values available during the next iteration.

Compute changes in time and height

Inside the while loop, the current value of t and the value stored in oldT are used to compute the change in time since the previous iteration. The current value of h and the value stored in oldH are used to compute the change in height since the previous iteration. These change values are saved in the variables named delT and delH .

Velocity is the ratio of the changes

In this case, the value in delH represents the displacement of the arrow during the time interval and the value stored in delT represents the length of the time interval. As you already know, the velocity isthe ratio of those two values. The value for velocity is computed along with the time and the height and then the script executes the next iteration of the while loop.

The while loop

The while loop in Listing 2 begins the same as in Listing 1 . After the new height value is computed, the script performs the computationsdescribed above to estimate and display the velocity for the time interval since the previous iteration.

In addition, the script saves the current values of t and h in oldT and oldH to be used to estimate the velocity during the next iteration of the while loop.

Finally, the time value is increased by the value stored in the variable named tInc , and control goes back to the top of the loop where the current value of height is tested to determine if it has become negative(meaning that the arrow has hit the ground).

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Game 2302 - mathematical applications for game development. OpenStax CNX. Jan 09, 2016 Download for free at https://legacy.cnx.org/content/col11450/1.33
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?

Ask