找到角度0-360 [英] finding angles 0-360
问题描述
需要数学问题的帮助:
i需要使用x和y来获得0度的真实角度。目前使用此方法来计算
im:
Need help with a math issue: i need to get the true angle from 0 degrees using x and y cordinates im using this at the moment:
Math.atan((x2-x1)/(y1-y2))/(Math.PI/180)
但 /(Math.PI / 180)
将结果限制在-90到90
i需要0-360
but /(Math.PI/180)
limits results from -90 to 90
i need 0-360
注意:我正在使用角度来指示方向:
note: I'm using the angle to indicate direction:
- 0 = up
- 90 =正确
- 135 = 45度右+下
- 180 =下来
- 270 =左
- 等
- 0=up
- 90=right
- 135=45 degree right+down
- 180=down
- 270=left
- etc
推荐答案
Math.atan将您限制在单位圆上最右边的两个象限。要获得完整的0-360度:
Math.atan limits you to the two rightmost quadrants on the unit circle. To get the full 0-360 degrees:
if x < 0 add 180 to the angle
else if y < 0 add 360 to the angle.
与我的相比,您的坐标系被旋转和反转(并与常规相比)。正x是向右,正y是向上。右边0度(x> 0,y = 0,向上90度(x = 0,y> 0)向上135度,向左(y> 0,x = -y)等。你的x轴和y轴指向?
Your coordinate system is rotated and inverted compared to mine (and compared to convention). Positive x is to the right, positive y is up. 0 degrees is to the right (x>0, y=0, 90 degrees is up (x=0,y>0) 135 degrees is up and to the left (y>0, x=-y), etc. Where are your x- and y-axes pointing?
这篇关于找到角度0-360的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!