finding angles 0-360

前端 未结 10 1840
清酒与你
清酒与你 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 16:12

    This should do the trick:

    1. If y2
    2. If < 0, add 360.

    Examples:

    (x1,y1) = 0

    (x2,y2) = (-1,1), atan() = -45, [add 360], 270
    (x2,y2) = (1,1), atan() = 45
    (x2,y2) = (1,-1), atan() = -45, [add 180], 135
    (x2 ,y2) = (-1,-1), atan() = 45, [add 180], 225
    

提交回复
热议问题