<< Chapter < Page Chapter >> Page >

The output

When you load your html file into your browser, it should produce the output shown earlier in Figure 3 . In other words, we know that the angle at the origin didn't change. What changed was the manner in which we computed the value ofthat angle.

Different approaches to the same solution

In Listing 2 , we used the length of the hypotenuse and the length of the opposite side, along with the arcsine method to compute the angle.

In Listing 4 , we used the length of the hypotenuse and the length of the adjacent side, along with the arccosine method to compute the angle.

Which approach should you use?

As would be expected, since the angle didn't change, both approaches produced the same result. Deciding which approach to use often depends onthe values that are available to use in the computation.

Sometimes you only have the lengths of the hypotenuse and the opposite side available, in which caseyou could use the arcsine. Sometimes you only have the lengths of the hypotenuse and the adjacent side available, in which case youcould use the arccosine. Sometimes you have the lengths of both the opposite side and the adjacent side in addition to thelength of the hypotenuse, in which case you can use either approach.

Both approaches use the length of the hypotenuse

It is important to note however that both of these approaches require you to have the length of the hypotenuse. Later in this module we will discuss thetangent and arctangent for an angle, which allows us to work with the opposite side and the adjacent side devoid of the length of the hypotenuse. (Of course, ifyou have the lengths of the opposite side and the adjacent side, you can always find the length of the hypotenuse using the Pythagorean theorem.)

Interesting cosine equations

The equations in Figure 6 are similar to equations in Figure 5 . The difference is that the equations in Figure 5 are based on the use of the sine of the angle and the opposite side whereas the equations in Figure 6 are based on the use of the cosine of the angle and the adjacent side.

As you can see in Figure 6 , if you know any two of the values for angle , adj , and hyp , you can find the other value. This is illustrated in the script shown in Listing 5 , which produces the output shown in Figure 7 .

Figure 6 . Interesting cosine equations.
cosine(angle) = adj/hyp angle = arccosine(adj/hyp)adj = hyp * cosine(angle) hyp = adj/cosine(angle)

Finding the length of the adjacent side

The code in Listing 5 is very similar to the code in Listing 2 . The main difference is that Listing 2 is based on the use of the sine of the angle and the length of the opposite side whereas Listing 5 is based on the use of the cosine of the angle and the length of the adjacent side.

Listing 5 . Finding the length of the adjacent side.
<!-- File JavaScript05.html --><html><body><script language="JavaScript1.3">function toRadians(degrees){ return degrees*Math.PI/180}//end function toRadians //============================================//function toDegrees(radians){ return radians*180/Math.PI}//end function toDegrees //============================================//var hyp = 5 var angDeg = 53.13var angRad = toRadians(angDeg) var cosine = Math.cos(angRad)var adj = hyp * cosine document.write("adjacent = " + adj + "<br/>") hyp = adj/cosinedocument.write("hypotenuse = " + hyp + "<br/>")</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