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
1 Answer
Reset to default 10var 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
版权声明:本文标题:Performing Trigonometry in Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741498500a2381944.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论