函数
import math
def cal_dis(latitude1,longitude1,latitude2,longitude2):
latitude1 = (Math.PI/180)*latitude1
latitude2 = (Math.PI/180)*latitude2
longitude1 = (Math.PI/180)*longitude1
longitude2= (Math.PI/180)*longitude2
#因此AB两点的球面距离为:{arccos[sinb*siny+cosb*cosy*cos(a-x)]}*R
#地球半径
global R = 6378.1;
d = math.acos(math.sin(latitude1)*math.sin(latitude2)+\
math.cos(latitude1)*math.cos(latitude2)*math.cos(longitude2-longitude1))*R
return d;
}
实现了根据输入两点经纬度,计算这两点距离的函数,但是在实际操作过程中,出现了报错:
下面是会报错的数据集:
经过搜索相关文章,最终发现是由于acos(x)中的x越界引起的。
语法
方法的语法:
Highlighter_972490" class="SyntaxHighlighter py" style="width:651.111145019531px;line-height:25.2000007629395px;overflow:auto !important;">
nofollow" class="toolbar_item command_help help" style="text-decoration:none;color:rgb(0,102,153);border:0px !important;line-height:1.1em !important;overflow:visible !important;text-align:center !important;vertical-align:baseline !important;min-height:auto !important;display:block !important;background:none !important;">?
总结
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您喜欢交流学习经验,点击链接加入交流1群:1065694478(已满)交流2群:163560250