k-means 算法的支持函数:球面距离计算(补全代码) """ Parameters: vecA - 点A向量 vecB - 点B向量 Returns: 球面距离 """ #d = R * arccos(sin(纬度1) * sin(纬度2) + cos(经度1) * cos(经度2) * cos(经度2 - 经度1)) #R=6371(地球半径) def distSLC(vecA, vecB):
时间: 2024-03-11 09:50:51 浏览: 92
求球面距离
5星 · 资源好评率100%
```python
from numpy import *
def distSLC(vecA, vecB):
# 地球半径
R = 6371.0
# 将经纬度转换成弧度
radLatA, radLonA = radians(vecA[0]), radians(vecA[1])
radLatB, radLonB = radians(vecB[0]), radians(vecB[1])
# 计算经纬度的差值
a = sin(radLatA) * sin(radLatB)
b = cos(radLatA) * cos(radLatB) * cos(radLonB - radLonA)
# 计算球面距离(单位:千米)
d = R * arccos(a + b)
return d
```
阅读全文