簡體   English   中英

查找包含任意坐標列表的voronoi區域

[英]Finding voronoi regions that contain a list of arbitrary coordinates

我正在使用一種算法,該算法對於每次迭代,需要找到一組arbirary協調所屬的Voronoi圖的哪個區域。 也就是說,每個坐標位於哪個區域內。 (我們可以假設所有坐標都屬於一個區域,如果這有任何區別的話。)

我還沒有任何適用於Python的代碼,但偽代碼看起來像這樣:

## we are in two dimensions and we have 0<x<1, 0<y<1.

for i in xrange(1000):
  XY = get_random_points_in_domain()
  XY_candidates = get_random_points_in_domain()
  vor = Voronoi(XY) # for instance scipy.spatial.Voronoi
  regions = get_regions_of_candidates(vor,XY_candidates) # this is the function i need

  ## use regions for something

我知道scipy.Delaunay有一個名為find_simplex的函數,它會在Delaunay三角剖分中完成我想要的簡單操作,但是我需要Voronoi圖,並且我希望避免構建它們。

問題

1.是否有某種類型的庫可以讓我輕松完成這項工作?

2.如果沒有,是否有一個好的算法可以讓我有效地做到這一點?

更新

Jamie的解決方案正是我想要的。 我有點尷尬,雖然我自己也沒想過......

您無需為此實際計算Voronoi區域。 根據定義,集合中一個點周圍的Voronoi區域由更接近該點的所有點組成,而不是集合中的任何其他點。 所以你只需要計算距離並找到最近的鄰居。 使用scipy的cKDTree你可以做到:

import numpy as np
from scipy.spatial import cKDTree

n_voronoi, n_test = 100, 1000

voronoi_points = np.random.rand(n_voronoi, 2)
test_points = np.random.rand(n_test, 2)

voronoi_kdtree = cKDTree(voronoi_points)

test_point_dist, test_point_regions = voronoi_kdtree.query(test_points, k=1)

test_point_regions現在保存一個shape (n_test, 1)數組,其中(n_test, 1)中的點voronoi_points最接近每個test_points

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM