Inside Collection (Course): GAME 2302  Mathematical Applications for Game Development
Summary: The purpose of this module is to explain variable velocity and acceleration.
This module is part of a series of modules designed for teaching the physics component of GAME2302 Mathematical Applications for Game Development at Austin Community College in Austin, TX. (See GAME 23020100: Introduction for the first module in the course along with a description of the course, course resources, homework assignments, etc.)
The purpose of this module is to explain variable velocity and acceleration.
I recommend that you open another copy of this document in a separate browser window and use the following links to easily find and view the Images and Listings while you are reading about them.
I will provide an introduction to variable velocity, acceleration, and the acceleration of gravity in this section. I will provide exercises on those topics in the next section.
What is velocity?
To review, you learned in an earlier module that velocity is the rate of change of position. Since displacement is a change in position, velocity is also the rate of displacement.
Uniform versus variable velocity
Previous modules have dealt exclusively with uniform velocity. However, many situations in life involve variable velocity and acceleration. For example, the simple act of stopping an automobile at a traffic light and then resuming the trip once the light turns green involves variable velocity and acceleration.
Three equations
I will explain both of these topics in this module using three wellknown physics equations that deal with the displacement of a projectile in a vacuum under the influence of gravity .
The equation that we will spend the most time on is
h = v0*t + 0.5*g*t^2
where
(I will provide the other two equations later .)
Everyone is familiar with the acceleration that occurs when a motor vehicle speeds up or slows down. When the vehicle speeds up very rapidly, the positive acceleration forces us against the back of the seat. (This involves the relationship among force, mass, and acceleration, which will be the subject of a future module.)
If the vehicle slows down very rapidly or stops suddenly, the negative acceleration may cause us to crash into the windshield, the dashboard, or a deployed airbag.
The accelerator pedal
A common name for the pedal that causes gasoline to be fed to the engine is often called the accelerator pedal because it causes the vehicle to speed up. (However, I have never heard anyone refer to the pedal that causes the vehicle to slow down as the deceleration pedal. Instead, it is commonly called the brake pedal.)
Definitions
Displacement is a change in position.
Velocity is the rate of change of position or the rate of displacement .
Acceleration is the rate of change of velocity .
Jerk is the rate of change of acceleration (not covered in this module).
According to this author , there is no universally accepted name for the rate of change of jerk .
The algebraic sign of acceleration
When the velocity of a moving object increases, that is viewed as positive acceleration. When the velocity of the object decreases, that is viewed as negative acceleration.
Uniform or variable acceleration
Acceleration may be uniform or variable. It is uniform only if equal changes in velocity occur in equal intervals of time.
A vector quantity
Acceleration has both direction and magnitude. Therefore, acceleration is a vector quantity.
The units for acceleration
The above definition for acceleration leads to some interesting units for acceleration. For example, consider a situation in which the velocity of an object changes by 5 feet/second in a onesecond time interval. Writing this as an algebraic expression gives us
(5 feet/second)/second
Multiplying the numerator and the denominator of the fraction by 1/second gives us
5 feet/(second*second)
This is often written as
5 feet/second^2
which is pronounced five feet per second squared.
The exercises in the remainder of this module are based on the following two assumptions:
Let's examine the validity of these two assumptions.
Newton's law of universal gravitation
This law states that every point mass in the universe attracts every other point mass with a force that is directly proportional to the product of their masses and inversely proportional to the square of the distance between them. (Separately it has been shown that large spherically symmetrical masses attract and are attracted as if all their mass were concentrated at their centers.)
Effect of gravity versus altitude
An object at the surface of the earth is approximately 3963 miles from the center of the earth. An object that is six miles above the surface of the earth (typical flying altitude for a passenger plane) is approximately 3969 miles from the center of the earth.
Therefore, (if I didn't make an arithmetic error) the gravitational attraction between the earth and that object changes by less than 0.5 percent when the object is transported from the surface of the earth to a position that is six miles above the surface of the earth.
For practical purposes, therefore, we can assume that the acceleration of gravity is constant up to at least 32000 feet above the surface of the earth.
Acceleration is independent of mass
Newton's law, as applied to the gravitational attraction of the earth, expressed in algebraic terms, looks something like the following :
f =E*m/d^2
where
Force equals mass times acceleration
It is a wellknown principle of physics that an object that is free to move will move and will accelerate when subjected to a force. The acceleration of the object will be proportional to the force and inversely proportional to its mass. In other words,
a = f/m
where
By multiplying both sides of the equation by m, we get a more common presentation of this relationship, which is
f = m*a
where the symbols mean the same as listed above .
A ratio of two different forces of gravity
Now let's use the equation from above to form a ratio of the forces exerted on two different masses by the earth, assuming that both masses are the same distance from the center of the earth.
f1/f2 =(E*m1/d^2)/(E*m2/d^2)
Cancel like terms to simplify
If we cancel like terms from the numerator and denominator of the expression on the right, we can simplify the ratio to
f1/f2 = m1/m2
Replacing the forces on the left by the expression from above , we get
m1*a1/m2*a2 = m1/m2
Multiplying both sides by m2/m1 we get
a1/a2 = 1
or
a1 = a2
This shows that the acceleration resulting from the gravitational force exerted on two objects that are equally distant from the center of mass of the earth is the same regardless of the differences in mass of the two objects.
I will present and explain several different scenarios based on the above assumptions in this section.
An archer that is six feet tall shoots an arrow directly upward with a velocity of 100 feet per second. Assume the arrow is at a height of 6 feet when it leaves the bow. Also ignore the effects of air resistance.
Plot height versus time
Use your graph paper and plot the height of the arrow on the vertical axis versus time on the horizontal axis. Plot one point each 0.25 seconds. Allow for a maximum time value of about 7 seconds and a maximum height value of about 165 feet.
Your plot should look something like the curve in Image 1 .
Image 1: Graph for variable velocity exercise #1. 

Create a script
Let's analyze this situation using a script. Copy the code shown in Listing 1 into an html file and open the file in your browser.
Listing 1: Variable velocity exercise #1. 


Screen output
The text shown in Image 2 should appear in your browser window when you open the html file in your browser.
Image 2: Screen output for Listing #1. 


Analysis of the output
Your curve should begin at a height of 6 feet and the height should increase on a pointbypoint basis out to about 3 seconds. The maximum height should occur around 3 seconds and should then start decreasing. The height should go to zero between 6.25 seconds and 6.5 seconds.
Not a trip to outer space
As you are probably aware, shooting an arrow upward does not cause the arrow to go into outer space, unless the arrow is selfpropelled and manages to reach a velocity commonly known as the "escape velocity."
Instead, for any practical value of initial velocity (neglecting air resistance), gravitational attraction will eventually cause the arrow to slow down, reverse course, and fall back to earth with continually increasing velocity until it strikes the earth and stops. That is the message conveyed by the plot of height in Image 1 and the output from the script shown in Image 2 .
The maximum height
At about 3 seconds and a height of about 161 feet, the kinetic energy provided by the initial velocity will have been dissipated by the gravitational attraction of the earth. At that point, the arrow won't go any higher. Instead, it will start falling back toward the earth. Somewhere around 6.25 seconds, it will strike the earth.
The shape of the curve
The shape of this curve is controlled by only two factors: the initial velocity of the arrow and the gravitational attraction of the earth. The archer has some degree of control over the initial velocity, but has no control over the gravitational attraction of the earth.
In theory, in the absence of an atmosphere, if the arrow is shot straight up, the arrow should land in the same place from which it was shot. In practice in the real world, wind and other factors would probably prevent that from happening.
Variable velocity
We learned in an earlier module that if velocity is uniform, the displacement should be the same during each successive equal interval of time. However, we can see from Image 2 that is not true in this case. For example, Image 3 shows the displacement versus time for the first five time intervals and we can see that it is anything but uniform.
Image 3: Displacement versus time for first five time intervals. 


Successively decreasing or increasing displacement
Referring back to Image 2 (along with Image 3 ), we see that the displacement during the first 0.25 second time interval was 24 feet, but the displacement between 2.75 seconds and 3.0 seconds was only 1.9 feet, Furthermore, the displacement was 0.2 feet during the interval between 3 seconds and 3.25 seconds indicating that the arrow had begun falling back to the earth.
As you can see in Image 2 , from that point until contact with the ground, the displacement increased during each 0.25 second interval.
In this case, the velocity clearly wasn't uniform. Instead it was variable. The velocity decreased as the arrow was going up, and increased as the arrow was falling back down.
Measuring variable velocity in the real world
Measuring variable velocity in the real world can be difficult. What you need to do is to measure the displacement of an object in as short a time interval as possible and then divide the displacement by the value of the time interval. If you can do this at enough points in time, you can construct curves that represent the variable velocity to which the object is being subjected.
Estimating variable velocity graphically
Assuming that you are able to create a plot of displacement versus time at closelyspaced points, you can estimate the variable velocity curve by connecting each pair of points with a straight line and measuring the slope of each such straight line segment. An estimate of the velocity during the interval defined by a pair of points is the slope of the line that connects those points. The closer the points are, the better will be the estimate of the velocity at a point half way between those two points.
In the situation where you are able to collect enough data to draw a smooth curve of displacement versus time, the instantaneous velocity at any point on that curve is the slope of a line that is tangent to the curve at that point. Note, however, that the construction of such a tangent line is difficult.
Units of velocity
If may recall from your high school geometry course that the slope of a line is given by the "rise over run." In other words, the slope of the line is the ratio of the height to the base of a right triangle for which the hypotenuse is on or parallel to the line.
Estimate some variable velocity values
At this point, I encourage you to use an object with a straight edge, place it firmly on two points that define a time interval on your graph, estimate the slope of the edge, and record that slope as your estimate of the velocity at the center of that time interval. We will do something similar in our script.
Explanation of the code
The code in Listing 1 begins by declaring and initializing values to contain the parameters of the problem:
Working variables
Following that, the code in Listing 1 declares and initializes two working variables for time and distance that will change as the program progresses.
Then Listing 1 declares and initializes a variable named sp that is used solely to insert spaces between the columns in the output display.
A while loop
A while loop is used to evaluate the equation given earlier , to compute and display the height of the arrow every 0.25 seconds for as long as the arrow is above the ground (height is positive). The loop continues to iterate and display time and height values in two separate columns (see Image 2 ) until the computation produces one negative height value.
When the test at the top of the while loop determines that the previouslycomputed value for height was negative,
This is not a complicated script in comparison with some of the scripts that were presented in earlier modules.
Given the output shown in Image 2 , you should be able to estimate and plot the velocity of the arrow on the same graph by dividing the displacement during each time interval by the value of the time interval.
Estimating variable velocity with a computer model
Let's write a script that approximates the graphic procedure that I described above.
Copy the code from Listing 2 into an html file and open the file in your browser.
Listing 2: Variable velocity exercise #2. 


Screen output
The text shown in Image 4 should appear in your browser window when the html file opens in your browser.
Image 4: Screen output for Listing #2. 


A graphical representation of velocity
The velocity values shown in Image 4 are plotted in Image 1 along with the height values and the acceleration values, which will be computed shortly..
Analysis of the results
The difference between Image 2 and Image 4 is the addition of a column of velocity information on the right in Image 4 . As you can see, the velocity begins with a positive value of 100 feet/second at the top of the velocity 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. That straight line crosses the horizontal axis going from positive territory into negative territory about half way between the original release of the arrow and the 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:
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 iteration to 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 is the 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 computations described 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).
To repeat the earlier definition, acceleration is the rate of change of velocity.
You learned earlier that velocity is the rate of change of position. Then you learned that we can estimate the velocity of a moving object at a point in time by determining the slope of a curve that plots the position of the object versus time at that particular point in time.
Positive and negative velocity
Positive slopes indicate positive velocity and negative slopes indicate negative velocity. In the case of our arrow, the velocity went to zero and switched from positive to negative at the point where the arrow reached its maximum height and began to fall back toward the earth. In a math class, that point would likely be referred to as an inflection point on the curve of position versus time.
Estimating acceleration
We can extend that procedure to estimate the acceleration of a moving object at a point in time by determining the slope of a curve that plots the velocity of the object versus time at that particular point in time. Positive slopes indicate positive acceleration and negative slopes indicate negative acceleration.
Estimate some velocity values graphically
If you have the velocity curve from Image 4 plotted on your graph, I recommend that you estimate and record the slope and hence the acceleration at a few points. That should be easy to do in this case, because the velocity curve should be a straight line with a negative slope.
A constant acceleration value
If the velocity curve is a straight line with a negative slope, and if the acceleration at any point in time is equal to the slope of the velocity curve, that means that the acceleration has a constant negative value throughout the time interval of interest. In fact, you should find that the value of the acceleration is approximately 32.2 feet/second^2, which is known as the acceleration of gravity .
Create a script
Copy the code from Listing 3 into an html file and open that file in your browser.
Listing 3: Acceleration of gravity exercise #1. 


Screen output
The text shown in Image 5 should appear in your browser window when the html file is opened in your browser.
Image 5: Screen output for Listing #3. 


A graphical representation of acceleration
The acceleration values shown in Image 5 are plotted in Image 1 along with the height values and the velocity values.
Analysis of the results
The main difference between Image 5 and Image 4 is the addition of an acceleration column on the right in Image 5 . (In addition, I abbreviated feet and seconds as ft and sec, and reduced the space between columns to make it all fit in the available space.)
Except for the first two values at the top of the acceleration column, every acceleration value is 32.2 ft/(sec*sec). This is what we predicted earlier when we observed that the velocity curve is a straight line with a constant negative slope. (Note that the procedure used to estimate the acceleration did not allow for an accurate estimate of acceleration for the first two values in the acceleration column.)
Free fall
According to Wikipedia , free fall is any motion of a body where gravity is the only force acting upon it.
Since this definition does not specify velocity, it also applies to objects initially moving upward (which is the case with our arrow that was shot upward).
Free fall was demonstrated on the moon by astronaut David Scott on August 2, 1971. He simultaneously released a hammer and a feather from the same height above the moon's surface. The hammer and the feather both fell at the same rate and hit the ground at the same time. This demonstrated Galileo's discovery that in the absence of air resistance, all objects experience the same acceleration due to gravity.
By the way, it is no accident that the value shown for acceleration in Image 4 matches the value specified for the acceleration of gravity near the beginning of the code in Listing 3 .
Analysis of the code
The code in Listing 3 is very similar to the code in Listing 2 with the addition of the code necessary to estimate the acceleration values on the basis of the slope of the velocity curve.
The code that estimates the acceleration in Listing 3 is so similar to the code that estimates the velocity in Listing 2 that I won't bore you by explaining the code in detail.
However, there is one bit of new code that is worthy of note. Without going into detail as to the reasons why, this procedure is incapable of accurately estimating the slope of the velocity curve during the first two time intervals. Therefore, an if statement was written into the while loop to force the acceleration estimate to be zero for the first two time intervals.
In the previous exercises, the arrow was shot straight up in the air. However, that is rarely the case. Normally, an arrow is shot in an attempt to strike a target some horizontal distance away.
A more realistic scenario
Let's modify our scenario such that the archer shoots the arrow with an initial velocity of 100 feet per second at an angle of 45 degrees relative to the horizontal axis. We will compute and plot the horizontal and vertical position of the arrow at uniform increments in time from the beginning to the end of its trajectory.
Motion of a projectile with uniform acceleration
The following equation describes the straightline motion of a projectile with uniform acceleration .
d = v0*t +0.5*a*t^2
where
As usual, the units for distance, time, velocity, and acceleration must be consistent with one another.
Shooting the arrow straight up
If we shoot an arrow straight up, as was the case in the previous exercises, the initial velocity doesn't have a horizontal component. Instead, the initial velocity has only a vertical component and the corresponding motion of the arrow has only a vertical component. In other words, the arrow goes straight up and it comes down in the same spot.
Shooting the arrow other than straight up
However, if we shoot the arrow in a direction other than straight up or straight down, the initial velocity has both a vertical component and a horizontal component. Therefore, the resulting motion has both a vertical component and a horizontal component.
To determine the position of the arrow at some time after it is released, we must determine both the vertical and the horizontal component of its motion.
Compute vertical and horizontal components independently
The equation given above can be used to compute the vertical and horizontal components of motion independently of one another. This approach can be used to give us the position as a function of time along each axis. We can then use that information to determine and plot the position of the arrow in xy space at one or more points in time.
Vertical and horizontal motion components are independent
It is important to understand that the vertical and horizontal components of motion are independent of one another. In other words, changing the vertical component of motion doesn't effect the horizontal motion and changing the horizontal component of motion doesn't effect the vertical motion. The overall motion seen by an observer is the superposition of the two.
Create a script
Please copy the code shown in Listing 4 into an html file and open the file in your browser.
Listing 4: Acceleration of gravity exercise #2. 


Screen output
The text shown in Image 6 should appear in your browser when you open the html file in your browser.
Image 6: Screen output for Listing #4 at 45 degrees. 


A graphical representation of the trajectory
Image 7 shows the trajectory of the arrow for firing angles of 45 degrees and 60 degrees. The vertical axis shows the height in feet and the horizontal axis shows the flight distance in feet.
Image 7: Trajectory for two different firing angles. 

Analysis of the output
Image 6 shows the x and y coordinates of the arrow's position every 0.25 seconds from the time that it is released until it strikes the ground a little less than 4.5 seconds later. This is the data for the case where the firing angle was 45 degrees.
Compute for a different angle
Next, I recommend that you modify the script by changing the value of the variable named ang from 45 degrees to 60 degrees and load the modified version of the html file into your browser. This should produce the output shown in Image 8 . This output is also plotted in Image 7 .
Which arrow went higher?
Which arrow went further along the horizontal axis?
Image 8: Screen output for Listing #4 at 60 degrees. 


Perhaps you could do the same thing for some other launch angles and determine which launch angle provides the greatest horizontal range and which launch angle provides the greatest vertical height.
For example, how far does the arrow fly when launched at an angle of 0 degrees from a height of 6 feet?
Analysis of the code
The code in this script treats the horizontal and vertical components of motion independently and uses the equation given above to determine the position along that axis as a function of time every 0.25 seconds.
Common parameter values
The code in Listing 4 begins by defining common parameter values for the firing angle, the time increment at which coordinate values will be computed and displayed, and the initial velocity of the arrow in the firing direction.
Horizontal and vertical parameters
Following that, the code in Listing 4 defines horizontal parameters and vertical parameters that will be used to compute the horizontal and vertical components of motion respectively.
Horizontal acceleration
The horizontal acceleration is set to zero. In the absence of air resistance, there is nothing to cause the horizontal component of the arrow to speed up or slow down until it stops suddenly when it hits the ground.
Vertical acceleration
The vertical acceleration is set to the acceleration of gravity at the surface of the earth, which is the same value used for the previous exercises in this module.
Decompose the initial velocity
The cosine and sine functions are used to decompose the initial velocity into horizontal and vertical components of velocity.
Initial horizontal and vertical positions
Finally, the horizontal position when the arrow is released is set to 0 and the vertical position is set to 6 feet, approximately the height of the release point for an archer that is six feet tall.
Working variables
After defining the horizontal and vertical parameters, the code in Listing 4 declares working variables for time, horizontal position (x), and vertical position (y).
A while loop
A while loop is used to iterate for as long as the arrow is above the ground.
During each iteration, the equation given above is evaluated twice, once to determine the height of the arrow and once to determine the horizontal position of the arrow at the current time.
Time starts at 0, and increments by +0.25 seconds during each iteration.
The document.write method is called inside the while loop to display the results shown in Image 6 .
A quadratic equation
Now let's turn things around and approach the problem from a different viewpoint. If we subtract d from both sides of the motion equation given above , replace a by g to avoid confusion later, and then rearrange the terms, we get the following equation :
0.5*g*t^2+v0*td = 0
where
In this form, you may recognize this as a standard quadratic equation which is often written as
a*t^2 + b*t + c = 0
(Now you know why I replaced the acceleration term a by the acceleration term g earlier. I need to use the symbol a in the standard quadratic equation.)
Standard solution for a quadratic equation
Given values for a, b, and c, you should know that the solution for determining the values for t is to find the roots of the equation.
There are two roots (hence two values for t). You should also know that the two roots can be found by evaluating the quadratic formula in two forms.
t1 = (b+Math.sqrt(b*b4*a*c))/(2*a);
t2 = (bMath.sqrt(b*b4*a*c))/(2*a);
Using the solution
Relating the coefficients in the standard motion equation to the coefficients in the standard quadratic equation gives us:
The scenario
Let's use the scenario posed in the first exercise in this module. In this scenario, an archer that is six feet tall shoots an arrow directly upward with a velocity of 100 feet per second. Assume that the arrow is at a height of 6 feet when it leaves the bow. Also ignore the effects of air resistance.
Referring back to Image 1...
We learned from the table in Image 2 that the arrow was at a height of 89.9 feet at 1 second on the way up from the surface of the earth, and was at a height of 89.9 feet again on the way down at approximately 5.2 seconds.
Let's pretend that we don't have the table in Image 1 and write a script that uses the quadratic form of the standard motion equation along with the quadratic formula to compute the times that the arrow was at a height of 89.9 feet.
Do it also for the moon
To make the problem even more interesting, let's also cause the script to compute and display the times that the arrow was at a height of 89.9 feet assuming that the archer was standing on the surface of the moon instead of the earth.
An issue involving the initial height
The standard motion equation can be used to compute the time that the arrow has traveled to any specific height, relative to the height from which it was released. Therefore, since the arrow was released from a height of 6 feet and it initially traveled up, we need to determine the time at which it had traveled 83.9 feet to find the time that it was actually at 89.9 feet.
The JavaScript code
Please copy the code from Listing 5 into an html file and open the file in your browser.
Listing 5: Acceleration of gravity exercise #3. 


Screen output
The text shown in Image 9 should appear in the browser window when you open the html file in the browser.
Image 9: Screen output for Listing #5. 


A function named getRoots
The quadratic formula isn't very complicated, but it is fairly tedious and easy to type incorrectly. Therefore, I decided to encapsulate it in a function that we can copy into future scripts saving us the need to type it correctly in the future.
Listing 5 begins with the definition of a function named getRoots that receives the parameters a, b, and c, and returns the roots of the quadratic equation in a twoelement array.
Real or imaginary roots
The roots of a quadratic equation can be either real or imaginary. If the roots are imaginary, this function simply returns NaN (not a number) for each root.
The parameters of the problem
Following the definition of the getRoots function, Listing 5 declares and initializes several variables to establish the parameters of the problem, such as the acceleration of gravity on the earth and moon, the initial velocity of the arrow, etc.
The computed height versus the target height
The target height for the problem is 89.9 feet. Note that the variable named d contains that value less the initial height of 6 feet. Thus, the script will find the time at which the arrow has traveled 83.9 feet on the way up, and the time that it has traveled that same distance on the way back down.
Establish quadratic coefficients
The next three lines of code use the problem parameters to establish values for the standard coefficients of a quadratic equation, a, b, and c, as described above . Note that at this point in the script, the coefficient named a is based on the acceleration of gravity on earth. (Later, it will be changed to reflect the acceleration of gravity on the moon.)
Get the roots of the quadratic equation
Then the script calls the getRoots function, passing a, b, and c as parameters, and stores the returned array containing the roots in the variable named roots .
Following that, the script extracts the roots from the array and displays them as shown by the text in the upper half of Image 9 .
Repeat the process for the moon
Then Listing 5 sets the value of the coefficient named a to reflect the acceleration of gravity on the moon, repeats the process, and displays the results in the lower half of Image 9 .
Note that the arrow reaches the target height somewhat quicker on the moon due to the lower acceleration of gravity, and takes much longer to arrive at the same height on the way back down to the surface of the moon. Were we to create a chart similar to Image 2 for the moon, we would see that the arrow goes much higher before turning around and falling back to the surface of the moon.
You have learned how to use the following equation to solve various physics problems involving motion in a straight line with uniform acceleration so far in this module.
h = v0*t + 0.5*g*t^2
where
Some physics textbooks also list the following equations as being important .
v = v0 + g*t
v^2 = v0^2 + 2*g*h
where v is the velocity of the object and the other terms are the same as described above .
Let's do an exercise using the first of the two equations given above .
An individual on the surface of the earth shoots an arrow directly upward with a velocity of 100 feet per second. How many seconds elapse before the arrow turns and starts falling towards the surface of the earth. Ignore the effects of air resistance.
Create a script
Please copy the code from Listing 6 into an html file and open the file in your browser.
Listing 6: Exercise to find the velocity. 


Screen output
The text shown in Image 10 should appear in your browser window when you open the html file in your browser.
Image 10: Screen output for Listing #6. 


Analysis of the code
Compared to working through the solutions to the previous exercises, this one seems almost trivial.
After establishing values for the acceleration of gravity and the initial velocity of the arrow, the code in Listing 6 rearranges the first equation given above and solves for the value of time at which the velocity goes to zero. This is the point in time when the arrow turns from moving up and begins falling back toward the earth.
The results are shown in Image 10 . You should compare this result with Image 1 , which shows that the arrow reaches its maximum height at approximately 3 seconds, which agrees very well with the result shown in Image 10 .
Let's do an exercise using the second of the two equations given above .
An individual that is six feet tall standing on the surface of the earth shoots an arrow directly upward with a velocity of 100 feet per second. What is the maximum height achieved by the arrow before it turns and falls back towards the surface of the earth? Ignore the effects of air resistance.
Create a script
Please copy the code from Listing 7 into an html file and open the file in your browser.
Listing 7: Exercise to find the height. 


Screen output
The text shown in Image 11 should appear in your browser window when the html file is opened in your browser.
Image 11: Screen output for Listing #7. 


Analysis of the code
Once again, compared to working through the previous exercises, this one also seems almost trivial.
After establishing values for the acceleration of gravity, the initial velocity of the arrow, and the height at which the arrow was released, the code in Listing 7 rearranges the second equation given above and solves for the value of the height (relative to the release point) at which the velocity goes to zero. This is the point in the trajectory where the arrow turns from moving up and begins falling back toward the earth.
Note that in order to get the actual height, it was necessary to add the initial height of 6 feet to the computed height.
Compare the results
The results are shown in Image 11 . You should compare this result with Image 2 , which shows that the arrow reaches its maximum height at approximately 161.1 feet, which agrees very well with the result shown in Image 11 .
I encourage you to run the scripts that I have presented in this lesson to confirm that you get the same results. Copy the code for each script into a text file with an extension of html. Then open that file in your browser. Experiment with the code, making changes, and observing the results of your changes. Make certain that you can explain why your changes behave as they do.
This section contains a variety of miscellaneous information.
Financial : Although the Connexions site makes it possible for you to download a PDF file for this module at no charge, and also makes it possible for you to purchase a preprinted version of the PDF file, you should be aware that some of the HTML elements in this module may not translate well into PDF.
I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version of the module.
In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale on Amazon.com showing me as the author. I neither receive compensation for those sales nor do I know who does receive compensation. If you purchase such a book, please be aware that it is a copy of a module that is freely available on cnx.org and that it was made and published without my prior knowledge.
Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX.
end