1 回答

TA貢獻(xiàn)1830條經(jīng)驗 獲得超9個贊
感謝這里的耐心評論者,我了解到vor.vertices對于無限大的點的第一個索引將返回 -1。這會產(chǎn)生一個問題,因為 python 將 -1 視為列表或數(shù)組最后一個元素的索引。
我的問題的解決方案不是從vor.vertices.
我通過用draw_voronoi()以下代碼替換函數(shù)來實現(xiàn):
def draw_voronoi(pygame_surface):
# generate voronoi diagram
vor = __generate_voronoi()
# draw all the edges
for indx_pair in vor.ridge_vertices:
if -1 not in indx_pair:
start_pos = vor.vertices[indx_pair[0]]
end_pos = vor.vertices[indx_pair[1]]
pygame.draw.line(pygame_surface, (0, 0, 0), start_pos, end_pos)
這產(chǎn)生了這個圖像:
添加回答
舉報