admin管理员组

文章数量:1290307

How do I perform the following math problem in Javascript:

Tan(x) = 450/120;
x      = 75;
// In my calculator I use tan^-1(450/120) to find the answer
// How do I perform tan^-1 in javascript???

My javascript code is outputting incorrect results:

var x = Math.atan(450/120);
alert(x); // says x = 1.3101939350475555

// Maybe I am meant to do any of the following...
var x = Math.atan(450/120) * (Math.PI/2); // still wrong answer
var x = Math.tan(450/120);  // still wrong answer

How do I perform the following math problem in Javascript:

Tan(x) = 450/120;
x      = 75;
// In my calculator I use tan^-1(450/120) to find the answer
// How do I perform tan^-1 in javascript???

My javascript code is outputting incorrect results:

var x = Math.atan(450/120);
alert(x); // says x = 1.3101939350475555

// Maybe I am meant to do any of the following...
var x = Math.atan(450/120) * (Math.PI/2); // still wrong answer
var x = Math.tan(450/120);  // still wrong answer
Share Improve this question asked Apr 10, 2012 at 9:30 sazrsazr 25.9k70 gold badges213 silver badges386 bronze badges 2
  • 3 Is your calculator in degrees mode? Real men use radians. – J. Holmes Commented Apr 10, 2012 at 9:42
  • 1 In all seriousness, one full revolution around a unit circle is an arc with the distance of 2Pi, which not coincidentally is the measurement of that angle in radians. Understanding that, and the relationship of other trigonomic functions to the unit circle, will make your life a lot easier. – J. Holmes Commented Apr 10, 2012 at 10:01
Add a ment  | 

1 Answer 1

Reset to default 10
var x = Math.atan(450/120);

Gives the answer 75 degrees in radians, which is: 1.3101939350475555

To get the correct answer just convert to degrees:

var x = Math.atan(450/120) * (180/Math.PI);
alert(x); // says x is 75.06858282186245

本文标签: Performing Trigonometry in JavascriptStack Overflow