数学老师我对不起你。>_<
事情是这样的。工作中会遇到一种图,图上的点呈圆形分布,坐标原点就在圆心。我需要按照点钟方向把整张图划分成多个块,然后获知每一个点分别在几点钟方向(比如1~ 2点之间这样)
每个点的xy坐标我是知道的,所以就可以运用正切函数tan来得到我想要的信息——理是这么个理,可真搞起来竟然结结实实地算了大半天ε=(´ο`*)))唉
具体思路不多说,code的注释理写的很清楚了↓
import math
def get_clock_range(x, y):
"""
First, get angle between x axis (positive direction) and line of coordinate origin - point location.
- use math.atan2 to get it. But this function return radian, so need use math.degrees to convert it to degree.
- quadrant I + II: degree 0 ~ 180
- quadrant III + IV: degree 0 ~ -180 (not include 0 and -180)
Need convert negative angle value to positive one. So if angle<0, +360
Second, based on angle value, make sure the point loc is between clock m and n.
- set i is clock number which the point loc is pointed at, m <