【问题标题】:Is there any way to get radians with asin/acos/atan functions JavaScript?有没有办法用 asin/acos/atan 函数 JavaScript 获得弧度?
【发布时间】:2019-08-09 15:48:24
【问题描述】:

我目前正在使用 Math.js 库来处理数学方程。

我知道使用三角函数 sin()、cos()、tan() 可以使用“deg”或“rad”从弧度更改为度数。但是对于 arcs 函数 asin()、cos()、tan(),它似乎不起作用。 如果除了手动计算之外还有其他方法。

test= math.eval("sin(1 deg)"); //Works
test2 = math.eval("sin(1 rad)"); //Works

test3= math.eval("asin(1 deg)"); //Does not work
test4 = math.eval("asin(1 rad)"); //Does not work

【问题讨论】:

  • @King Stone 你能解释一下吗?
  • 我认为,javascript支持Math类,我们可以使用Math.asin(1)asin 函数我们不需要任何库
  • 是的,我知道,但我正在使用它
  • @EXMark2 JS 内置的Math 类与您使用的这个 Math.js 库不同。

标签: javascript math trigonometry math.js


【解决方案1】:

三角函数的参数(以及逆三角函数的返回值)是一个以弧度为单位的数字。要使用度数,请乘以或除以 Math.PI/180

Math.sin(45 * Math.PI/180) --> -.7071...

Math(Math.arctan(1)) * 180/Math.PI --> 45 (degrees)

如果您使用弧度,请不要乘以或除以该因子。

Math.asin(1) --> 1.57...  (radians)
Math.asin(1) * 180/Math.PI -->  90   (or something close; in degrees)

【讨论】:

  • 我实际上是在转换 asin() 中的值,这就是我得到错误结果的原因。谢谢
【解决方案2】:

你应该使用,

math.eval("asin(1)");

反正弦是以数字为输入值的反三角函数

正如documentation 所指,asin(x) 需要 number 值,而 deg 不是。

【讨论】:

  • 有什么方法可以使用 asin() 得到 1 的弧度值吗?
  • arcsin(sin(1)) 是你想要的,我明白了吧?
  • @alpsavrum - 这将给出接近 1.000 的值,它是弧度。 asinsin 是彼此的倒数。
猜你喜欢
  • 1970-01-01
  • 2014-03-20
  • 2016-12-04
  • 2021-08-26
  • 2023-04-04
  • 1970-01-01
  • 1970-01-01
  • 2011-03-13
  • 2011-04-24
相关资源
最近更新 更多