python实现已知两个点坐标求与正北夹角度数
代码如下:其中s(x_point_s,y_point_s),e(x_point_e,y_point_e)为两点坐标:
def calc_angle(x_point_s,y_point_s,x_point_e,y_point_e):
angle=0
y_se= y_point_e-y_point_s;
x_se= x_point_e-x_point_s;
if x_se==0 and y_se>0:
angle = 360
if x_se==0 and y_se<0:
angle = 180
if y_se==0 and x_se>0:
angle = 90
if y_se==0 and x_se<0:
angle = 270
if x_se>0 and y_se>0:
angle = math.atan(x_se/y_se)*180/math.pi
elif x_se<0 and y_se>0:
angle = 360 + math.atan(x_se/y_se)*180/math.pi
elif x_se<0 and y_se<0:
angle = 180 + math.atan(x_se/y_se)*180/math.pi
elif x_se>0 and y_se<0:
angle = 180 + math.atan(x_se/y_se)*180/math.pi
return angle
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。