我怎样才能让 sin、cos 和 tan 使用度数而不是弧度? [英] How can I get sin, cos, and tan to use degrees instead of radians?

查看:38
本文介绍了我怎样才能让 sin、cos 和 tan 使用度数而不是弧度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 JS 中使用数学时,我希望它的三角函数使用度值而不是弧度值.我该怎么做?

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);
}

请注意,sincos 等函数不返回角度,它们将角度作为输入.在我看来,拥有一个将度数输入转换为弧度的函数对您更有用,如下所示:

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))之类的事情.

which you could use to do something like tan(toRadians(45)).

这篇关于我怎样才能让 sin、cos 和 tan 使用度数而不是弧度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆