python读取如1 02917930254704324 0022895137821592182 -008114470668959266 -00588472702240990943 -10063152208304178 -014003678801063594 2137262707595156 011466382142044017形式的200个坐标点并找到坐标为0632085381780765101
可以使用以下代码来实现:
import math
# 目标坐标
target = (0.6320853817807651, 0.1625185725298671)
# 读取坐标点
points = []
with open('coordinates.txt', 'r') as file:
lines = file.readlines()
for line in lines:
data = line.strip().split()
point = (float(data[1]), float(data[2]))
points.append(point)
# 计算距离最近的点
min_distance = math.inf
closest_point = None
for point in points:
distance = math.sqrt((target[0] - point[0]) ** 2 + (target[1] - point[1]) ** 2)
if distance < min_distance:
min_distance = distance
closest_point = point
print(f"距离最近的点是:{closest_point}")
需要注意的是,上述代码假设坐标点保存在名为coordinates.txt的文件中,每个点占据一行,并且每个点的坐标用空格分隔。如果你的坐标点保存在其他文件中,需要将代码中的'coordinates.txt'替换为相应的文件路径
原文地址: http://www.cveoy.top/t/topic/h8hK 著作权归作者所有。请勿转载和采集!