<< Chapter < Page | Chapter >> Page > |
Convert paces to inches
Then Figure 5 shows the conversion factor (labeled f1 ) that can be used to convert a value expressed in paces to a value expressed in inches.
That conversion factor is applied to the original distance producing an output consisting of the same distance expressed in inches instead of paces. Thedistance is now 63360 inches.
Convert from inches to feet
Following that, f2 shows the conversion factor that can be used to convert a value expressed in inches to the same value expressed in feet.
That conversion factor is applied to the current distance value producing an output consisting of the same distance expressed in feet instead of inches. Thedistance is now 5280 feet.
Convert from feet to miles
Finally, Figure 5 shows the conversion factor (labeled f3 ) that can be used to convert a value expressed in feet to the same value expressed in miles.
That conversion factor is applied to the current distance value producing a final output consisting of the same distance expressed in miles instead of feet.That distance is now one mile (obviously I chose the numbers to make it come out that way).
That is the number that we were looking for.
Reverse the process
If a conversion factor X can be used to convert from A-units to B-units, the reciprocal of X can be used to convert from B-units back to A-units.
As you will see later, the conversion factor f4 shown in Figure 5 was computed as the product of the reciprocals of f1 , f2 , and f3 . The result is that the conversion factor labeled f4 can be used to convert a value expressed in miles to the same value expressed in paces (according to the pace-length for oneindividual).
That conversion factor was applied to the distance expressed in miles to produce the same distance expressed in paces. As you might have guessed, thisvalue of 2112 paces shown near the end of Figure 5 matches the value shown at the beginning of Figure 5 .
Analysis of the script
Now lets analyze the script code in Listing 1 that produced the text output shown in Figure 5 .
Listing 1 begins by declaring and initializing the variables d , d2 , and d3 , which are respectively,
Various values are displayed as the script executes using calls to the document.write method. You should have no difficulty identifythe code that displays the values, so I will skip over that code in this discussion.
Compute, save, and apply the conversion factor f1
Then Listing 1 declares a variable named f1 and populates it with the value of a conversion factor that can be used to convert paces to inches. Thisconversion factor is computed from the known relationship between paces and inches mentioned earlier.
The conversion factor named f1 is applied to the distance in paces converting it to a value that represents the same distance in inches (63360 inches).
Analysis of the units
The comment that reads
//pace*inch/pace = inch
is an analysis that shows the units that will result from applying the conversion factor to the distance at this point. As you can see, the paceterms will cancel and the result will be in inches.
Notification Switch
Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?