如何使用度数而不是弧度来获得sin,cos和tan? [英] How can I get sin, cos, and tan to use degrees instead of radians?
本文介绍了如何使用度数而不是弧度来获得sin,cos和tan?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在JS中使用数学时,我希望它的trig函数使用度数值而不是弧度值。我该怎么做?
When I'm working with math in JS I would like its trig functions to use degree values instead of radian values. How would I do that?
推荐答案
您可以使用这样的函数进行转换:
You can use a function like this to do the conversion:
function toDegrees (angle) {
return angle * (180 / Math.PI);
}
注意像 sin $ c $这样的函数c>,
cos
,依此类推不返回角度,它们将角度视为输入。在我看来,拥有一个将度数输入转换为弧度的函数会更有用,如下所示:
Note that functions like sin
, cos
, and so on do not return angles, they take angles as input. It seems to me that it would be more useful to you to have a function that converts a degree input to radians, like this:
function toRadians (angle) {
return angle * (Math.PI / 180);
}
你可以用它来做像 tan( toRadians(45))
。
这篇关于如何使用度数而不是弧度来获得sin,cos和tan?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文