Trigonometric functions: Difference between revisions

Line 576:
JavaScript's <tt>Math</tt> class contains all six functions and is automatically included as part of the language. The functions all accept radians only, so conversion is necessary when dealing with degrees. The <tt>Math</tt> class also has a <tt>PI</tt> constant for easy conversion.
 
<lang javascript>//Pi / 4 is 45 degrees. All answers should be the same.var
var radians = Math.PI / 4;, // Pi / 4 is 45 degrees. All answers should be the same.
var degrees = 45.0;,
var arcsin sine = Math.asin(Math.sin(radians));,
//sine
var arccos cosine = Math.acos(Math.cos(radians));,
window.alert(Math.sin(radians) + " " + Math.sin(degrees * Math.PI / 180));
var arctan tangent = Math.atan(Math.tan(radians));,
//cosine
arcsin = Math.asin(sine),
window.alert(Math.cos(radians) + " " + Math.cos(degrees * Math.PI / 180));
arccos = Math.acos(cosine),
//tangent
arctan = Math.atan(tangent);
window.alert(Math.tan(radians) + " " + Math.tan(degrees * Math.PI / 180));
 
//arcsine
// sine
var arcsin = Math.asin(Math.sin(radians));
window.alert(Math.sin(radians)sine + " " + Math.sin(degrees * Math.PI / 180));
// cosine
window.alert(Math.cos(radians)cosine + " " + Math.cos(degrees * Math.PI / 180));
// tangent
window.alert(Math.tan(radians)tangent + " " + Math.tan(degrees * Math.PI / 180));
// arcsine
window.alert(arcsin + " " + (arcsin * 180 / Math.PI));
// arccosine
var arccos = Math.acos(Math.cos(radians));
window.alert(arccos + " " + (arccos * 180 / Math.PI));
// arctangent
var arctan = Math.atan(Math.tan(radians));
window.alert(arctan + " " + (arctan * 180 / Math.PI));</lang>
 
Anonymous user