finding angles 0-360

前端 未结 10 1850
清酒与你
清酒与你 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:02

    function angle(x1,y1,x2,y2)
    {
    eangle = Math.atan((x2-x1)/(y1-y2))/(Math.PI/180)
    if ( angle > 0 )
    {
      if (y1 < y2)
        return angle;
      else
        return 180 + angle;
    } else {
      if (x1 < x2)
        return 180 + angle;
      else
        return 360 + angle;
    }
    }
    

提交回复
热议问题