finding angles 0-360

前端 未结 10 1841
清酒与你
清酒与你 2020-12-25 15:16

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))/(Ma         


        
10条回答
  •  我在风中等你
    2020-12-25 15:59

    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. 
    

    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?

提交回复
热议问题