我正在尝试使用 scipy 包构建有界 Voronoi 图,在每次迭代中,我计算 Voronoi 单元的质心,并向质心移动一点(比如一些增量),并通过更新生成器点重新计算 Voronoi 图。当我尝试绘制更新的点时,我收到一个奇怪的错误,因为我绘制的点不是预期的位置。这是代码
import matplotlib.pyplot as pl
import numpy as np
import scipy as sp
import scipy.spatial
import sys
np.random.seed(1)
eps = sys.float_info.epsilon
n_robots = 10
robots = np.random.rand(n_robots, 2)
#print(robots)
bounding_box = np.array([0., 1., 0., 1.])
def in_box(robots, bounding_box):
return np.logical_and(np.logical_and(bounding_box[0] <= robots[:, 0],
robots[:, 0] <= bounding_box[1]),
np.logical_and(bounding_box[2] <= robots[:, 1],
robots[:, 1] <= bounding_box[3]))
def voronoi(robots, bounding_box):
i = in_box(robots, bounding_box)
points_center = robots[i, :]
points_left = np.copy(points_center)
points_left[:, 0] = …
Run Code Online (Sandbox Code Playgroud)