首页 > 编程语言 > 详细

计算多个点中距离最远的两个点 python

时间:2019-07-15 13:15:58      阅读:605      评论:0      收藏:0      [点我收藏+]
import numpy as np
from scipy import spatial


print("hello")
# test points
pts = np.random.rand(100, 2)
print(pts)
# two points which are fruthest apart will occur as vertices of the convex hull
candidates = pts[spatial.ConvexHull(pts).vertices]
# get distances between each pair of candidate points
dist_mat = spatial.distance_matrix(candidates, candidates)
# get indices of candidates that are furthest apart
i, j = np.unravel_index(dist_mat.argmax(), dist_mat.shape)
print(candidates[i], candidates[j])
# e.g. [ 1.11251218e-03 5.49583204e-05] [ 0.99989971 0.99924638]

计算多个点中距离最远的两个点 python

原文:https://www.cnblogs.com/ziytong/p/11188122.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!