【问题标题】:Find Inverse Tangent?求反正切?
【发布时间】:2017-02-24 14:01:48
【问题描述】:

我是 Javascript 新手,我正在尝试使用反正切来找到一条线与高架 y 上的 x 轴之间的角度(以度为单位)。我没有看到任何命令,所以我真的需要一些帮助。

【问题讨论】:

  • 你是说 arctanget 吗?

标签: javascript trigonometry processing.js


【解决方案1】:

使用Math.atan()函数,然后Math.toDegrees()乘以180/Math.PI将弧度转换为度数 找到答案啦here

后期编辑:

这是一个由 2 个点(AB)定义的 lineX axis 之间的角度计算示例。 第二条线的高度(与 X 轴平行)无关紧要,因为角度保持不变。

 /*
 * Calculates the angle between AB and the X axis
 * A and B are points (ax,ay) and (bx,by)
 */
function getAngleDeg(ax,ay,bx,by) {
  var angleRad = Math.atan((ay-by)/(ax-bx));
  var angleDeg = angleRad * 180 / Math.PI;
  
  return(angleDeg);
}

console.log(getAngleDeg(0,1,0,0));

【讨论】:

  • 我在 atan 中放了什么?都是3个x和y吗
【解决方案2】:

尝试使用Math.atan(以弧度为单位输出角度)和一些三角函数。

【讨论】:

    【解决方案3】:

    此类问题最好由the reference 回答。我在那里看到一堆三角函数,包括:

    • acos()
    • asin()
    • atan()
    • atan2()
    • cos()
    • degrees()
    • radians()
    • sin()
    • tan()

    【讨论】:

    • 这是来自ProcessingJS,不是JavaScript,有区别!
    • @DaMahdi03 是的,我知道。请注意问题中的processing.js 标签。
    • 也许写这个问题的人对 JavaScript 不太了解?
    • @DaMahdi03 抱歉,我不确定你想告诉我什么。这个问题被标记为processing.js,所以我用Processing.js 回答。对我来说似乎很合理。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 2011-12-10
    • 2022-01-14
    • 2022-01-26
    • 2019-07-23
    相关资源
    最近更新 更多