How to get angle of point from center point?

前端 未结 4 947
傲寒
傲寒 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:04

    Ah, easy mistake to make. atan returns the value in radians, not degrees. So you need to multiply the angle by 180/pi to get it back to degrees. You also need to change your dy to y0 - y to be consistent with your dx. Here's some corrected code.

    dx, dy = x0-x, y0-y
    angle_in_radians = atan2(dy,dx) # you don't need to cast to float
    angle_in_degrees = angle_in_radians * 180 / pi
    

提交回复
热议问题