<< Chapter < Page | Chapter >> Page > |
Note that the absolute value for the sine and the cosine of an angle is limited to a maximum value of 1.0. However, the tangent of an angle is not solimited. In fact, the tangent of 45 degrees is 1.0 and the tangent of 90 degrees is infinity. This results from the length of the adjacent side, which is thedenominator in the ratio, going to zero at 90 degrees.
Dividing by zero in a script is usually not a good thing. This is a pitfall that you must watch out for when working with tangents. I will provide code later that shows you how deal with this issue.
Computing the tangent
If we know the lengths of the opposite side and the adjacent side, we can compute the tangent and use it for other purposes later without having to knowthe value of the angle.
Conversely, if we know the value of the angle but don't know the lengths of the adjacent side and/or the opposite side, we can obtain the tangent valueusing a scientific calculator or lookup table and use it for other purposes later.
The tangent of an angle -- sample computation
Enter the following into the Google search box:
tan(53.13010235415598 degrees)
The following will appear immediately below the search box:
tan(53.13010235415598 degrees) = 1.33333333
This agrees with the ratio that we computed earlier .
The arctangent (inverse tangent) of an angle
The arctangent of an angle is the value of the angle having a given tangent value. (For example, as mentioned above, the arctangent of infinity is 90degrees and the arctangent of 1.0 is 45 degrees.) In other words, if you know the value of the tangent of an unknown angle, you can use a scientific calculator or lookup table to find the value of theangle.
For example, we know that the tangent of the angle at the origin on your 3-4-5 triangle is 1.333. From that, we can determine the value of the angle.
The arctangent of an angle -- sample computation
Enter the following into the Google search box:
arctan(4/3) in degrees
The following will appear immediately below the search box:
arctan(4/3) = 53.1301024 degrees
We can also write a JavaScript script to perform the calculation.
Getting the angle for a known tangent value using JavaScript
Please create an html file containing the code shown in Listing 6 and open it in your browser.
Listing 6 . Arctan of 3-4-5 triangle. |
---|
<!-- File JavaScript06.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 opp = 4
var adj = 3var ratio = opp/adj
var angRad = Math.atan(ratio)var angDeg = toDegrees(angRad)
document.write("radians = " + angRad + "<br/>")
document.write("degrees = " + angDeg)</script></body></html> |
The output from the script
Once again, when you open this file in your browser, the output shown in Figure 3 should appear in your browser window.
The code in Listing 6 is very similar to the code in Listing 2 . They both describe the same right triangle, so the output should be thesame in both cases.
Notification Switch
Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?