Java: Calculating the angle between two points in degrees

后端 未结 7 1667
故里飘歌
故里飘歌 2020-11-30 00:46

I need to calculate the angle in degrees between two points for my own Point class, Point a shall be the center point.

Method:

public float getAngle(         


        
7条回答
  •  伪装坚强ぢ
    2020-11-30 01:05

    angle = Math.toDegrees(Math.atan2(target.x - x, target.y - y));
    

    now for orientation of circular values to keep angle between 0 and 359 can be:

    angle = angle + Math.ceil( -angle / 360 ) * 360
    

提交回复
热议问题