How to get angle of point from center point?

前端 未结 4 943
傲寒
傲寒 2021-02-09 16:34

If I have 2 points (x0,y0) which is the center of the circle, and another point (x,y) (this is the red dot on the circle boundary in the image). How can I get the angle of the d

4条回答
  •  爱一瞬间的悲伤
    2021-02-09 17:14

    In addition to converting from radians, consider using atan2 instead of atan. Whereas atan will give the same answer for points on the opposite side of the circle, atan2 will give you the correct angle, taking into account the signs of both dx and dy. It takes two arguments:

    angle = math.degrees(math.atan2(y0 - y, x0 - x)) % 360
    

    Note that atan2 will return something between -pi and pi, or -180 degrees and 180 degrees, so the % 360 is to shift the result to your desired range.

提交回复
热议问题