In Javascript, I'd use Math.atan2(1.5, 5.0). To convert to degrees, use Math.atan2(1.5, 5.0)/(Math.PI/180). On Wikipedia: http://en.wikipedia.org/wiki/Atan2
For any real arguments x and y not both equal to zero, atan2(y, x) is the angle in radians between the positive x-axis of a plane and the point given by the coordinates (x, y) on it.
你必须小心之间的角度。反正切 atan(y / x) 将为您提供相对于正 x 轴的角度,但请确保这是您需要的。
You have to be careful about what the angles are between. Arctangent, atan(y / x), will give you the angle relative to the positive x-axis, but make sure that's what you need.
发布评论
评论(6)
在 Javascript 中,我会使用
Math.atan2(1.5, 5.0)
。要转换为度数,请使用Math.atan2(1.5, 5.0)/(Math.PI/180)
。在维基百科上:http://en.wikipedia.org/wiki/Atan2In Javascript, I'd use
Math.atan2(1.5, 5.0)
. To convert to degrees, useMath.atan2(1.5, 5.0)/(Math.PI/180)
. On Wikipedia: http://en.wikipedia.org/wiki/Atan2您需要
atan2
:You need
atan2
:与 x 轴的角度(以弧度为单位)由下式给出:
您还需要处理
vx < 0 。
如果您想要相对于正北的方位,那么您可能需要:
The angle in radians from the x-axis is given by:
You also need to handle the case
vx < 0
.If you want the bearing versus true north, then you might want:
该角度是 y / x 的反正切。许多语言的数学库中都有一个 4 象限反正切函数,它接受 x 和 y 参数。
The angle is the arctangent of y / x. Many languages have a 4-quadrant arctangent function in the math library that takes x and y arguments.
你必须小心之间的角度。反正切
atan(y / x)
将为您提供相对于正 x 轴的角度,但请确保这是您需要的。You have to be careful about what the angles are between. Arctangent,
atan(y / x)
, will give you the angle relative to the positive x-axis, but make sure that's what you need.斜率的反正切会给你你想要的。
The arc-tangent of the slope will give you what you want.