<< Chapter < Page Chapter >> Page >

Compute, save, and apply the conversion factor f2

Following that, a conversion factor named f2 is computed that can be used to convert a value expressed in inches to the same value expressed in feet. Thisconversion factor is based on the known fact that there are 12 inches in a foot.

The factor named f2 is applied to the distance that is now expressed in inches converting it to a new value that expresses the same distance in feet(5280 feet).

Analysis of the units

The comment that reads

//inch*feet/inch = feet

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 inchterms will cancel and the result will be in feet.

Compute, save, and apply the conversion factor f3

Following that, a conversion factor named f3 is computed that can be used to convert a value expressed in feet to the same value expressed in miles. Thisconversion factor is based on the known fact that there are 5280 feet in a mile.

The factor named f3 is applied to the distance that is now expressed in feet converting it to a new value that expresses the same distance in miles (1mile).

Analysis of the units

The comment that reads

//feet*mile/feet = mile

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 feet termswill cancel and the result will be in miles.

That satisfies the specifications

That satisfies the original program specification. However, I mentioned earlier that if a conversion factor X can be used to convert from A-units toB-units, the reciprocal of X can be used to convert from B-units back to A-units.

Reversing the process

Continuing with Listing 1 , the comment that reads

//(pace/inch)*(inch/foot)*(foot/mile) = pace/mile

shows the units that survive from a product of the reciprocals of f1 , f2 , and f3 . As you can see, after canceling out inches and feet, the result of multiplying the reciprocals of those three conversion factors is a new conversionfactor that can be used to convert a value expressed in miles to a new value that represents the same distance expressed in paces.

That conversion factor is applied to the distance in miles producing an output of 2112, which unsurprisingly, is the distance in paces that we startedoff with.

More substantive JavaScript examples

Assume that you drop a rock from a balloon at a height of 10000 feet above the ground, Further assume that the positive direction is up and the negativedirection is down.

What would be the height of the rock above the ground at the end of ten seconds? What would be the height of the rock at the end of twenty seconds?

An equation relating distance, acceleration, and time

As you will learn in a future module, the following equation gives the distance that the rock will travel as a function of time assuming that the initial velocity is zero . (The assumption is that the rock was simply dropped and not thrown .)

d = 0.5 * g * t^2

where

  • d is the distance traveled
  • g is the acceleration of gravity (approximately -32.2 ft/s^2)
  • t is time is seconds

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