zoukankan      html  css  js  c++  java
  • 计算多个点中距离最远的两个点 python

    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]
  • 相关阅读:
    杭电2081
    杭电2083
    杭电2084
    3/5/2014 cfb 小心
    116
    uva10003
    10815
    127
    674
    uva 13598
  • 原文地址:https://www.cnblogs.com/ziytong/p/11188122.html
Copyright © 2011-2022 走看看