求反正切?
Find Inverse Tangent?
我是 Javascript 的新手,我正在尝试使用反正切来求出直线与高架 y 上的 x 轴之间的角度(以度为单位)。我没有看到任何命令,所以我真的需要一些帮助。
尝试使用 Math.atan
(以弧度为单位输出角度)和一些三角函数。
使用Math.atan()
函数然后Math.toDegrees()
乘以180/Math.PI
将弧度转换为度
找到答案啦here
稍后编辑:
这里是计算由 2 个点(A
和 B
)定义的 line
和 X 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));
此类问题最好由 the reference 回答。我在那里看到了一堆三角函数,包括:
acos()
asin()
atan()
atan2()
cos()
degrees()
radians()
sin()
tan()
我是 Javascript 的新手,我正在尝试使用反正切来求出直线与高架 y 上的 x 轴之间的角度(以度为单位)。我没有看到任何命令,所以我真的需要一些帮助。
尝试使用 Math.atan
(以弧度为单位输出角度)和一些三角函数。
使用Math.atan()
函数然后乘以Math.toDegrees()
180/Math.PI
将弧度转换为度
找到答案啦here
稍后编辑:
这里是计算由 2 个点(A
和 B
)定义的 line
和 X 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));
此类问题最好由 the reference 回答。我在那里看到了一堆三角函数,包括:
acos()
asin()
atan()
atan2()
cos()
degrees()
radians()
sin()
tan()