<< Chapter < Page Chapter >> Page >

Referring back to Figure 1...

We learned from the table in Figure 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 theway down at approximately 5.2 seconds.

Let's pretend that we don't have the table in Figure 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.9feet 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 todetermine 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.

<!---------------- File JavaScript05.html ---------------------><html><body><script language="JavaScript1.3">document.write("Start Script<br/><br/>"); //The purpose of the getRoots function is to compute and// return the roots of a quadratic equation expressed in // the format// a*x^2 + b*x + c = 0 //The roots are returned in the elements of a two-element// array. If the roots are imaginary, the function // returns NaN for the value of each root.function getRoots(a,b,c){ var roots = new Array(2);roots[0] = (-b+Math.sqrt(b*b-4*a*c))/(2*a);roots[1] = (-b-Math.sqrt(b*b-4*a*c))/(2*a);return roots; }//end getRoots//Initialize the problem parameters. var gE = -32.2;//gravity in ft/sec*sec on Earthvar gM = -32.2*0.167;//gravity in ft/sec*sec on the Moon var v0 = 100;//initial velocity in ft/secvar d0 = 6;//initial height in feet var d = 89.9-d0;//target height corrected for initial height//Equate problem parameters to coefficients in a // standard quadratic equation.var a = 0.5*gE; var b = v0;var c = -d; //Solve the quadratic formula for the two times at which the// height matches the target height corrected for the // initial height.var roots = getRoots(a,b,c); //Extract the two time values from the array.var t1 = roots[0];//time in secondsvar t2 = roots[1];//time in seconds//Display the results for the earth. document.write("On Earth<br/>"); document.write("Arrow is at " + (d+d0) + " feet at " +t1.toFixed(2) + " seconds" + "<br/>"); document.write("Arrow is at " + (d+d0) + " feet at " +t2.toFixed(2) + " seconds" + "<br/><br/>"); //Compute and display for the moon//Adjust the value of a to represent the acceleration // of gravity on the moona = 0.5*gM; //Solve the quadratic formula for the two times at which the// height matches the target height corrected for the // initial height.roots = getRoots(a,b,c); //Extract the two time values from the array.var t1 = roots[0];//time in secondsvar t2 = roots[1];//time in seconds//Display the results. document.write("On the Moon<br/>"); document.write("Arrow is at " + (d+d0) + " feet at " +t1.toFixed(2) + " seconds" + "<br/>"); document.write("Arrow is at " + (d+d0) + " feet at " +t2.toFixed(2) + " seconds" + "<br/><br/>"); document.write("End Script");</script></body></html>

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