Python,如何在2D空间中找到下一个最近的可用点?

问题描述 投票:0回答:1

给出起始数组[[0,0],[1、0],[0、1]]。如何在python中的2D空间中找到下一个最近的可用点(按距(0,0)的距离)?在pic1中找到下一个可用的红点(按距(0,0)的距离)?在追加数组之后,在pic2中再次在红点中找到下一个可用的对象(按与(0,0)的距离),并保持增长?

**pic1**

pic2

python algorithm matrix artificial-intelligence nearest-neighbor
1个回答
0
投票
中找到下一个可用的对象(到(0,0)的距离)

伪代码:

Sort by Min(delta_x, delta_y)
set `best_distance` to DOUBLE.MAX
as long as entries are below `best_distance`, 
    get squared distance d2 = delta_x^2  + delta_x^2;
    if best_distance>d2 
      best_distance = d2 
© www.soinside.com 2019 - 2024. All rights reserved.