![](/img/trans.png)
[英]Python, section of a tetrahedralized (scipy.Delaunay) 3D cloud of points
[英]Scipy 3D Delaunay. Different results when translating the set of points
我認為給定一組點,3D Delaunay.network 將是唯一的。 但是移動所有點(不改變相對距離)會得到不同的結果。
import numpy as np
from scipy.spatial import Delaunay
points = np.array([ [-0.6, -0.1, -1.5], [0, 0, 0], [-1,-1,-1],[1, 0, 1], [1, 1, 2], [0, 1.1, -1]])
points = points+[0,5,0] #for translation
tri = Delaunay(points)
我比較了結果和連接矩陣,它們是不同的。
案例 0。沒有翻譯。 連接矩陣。
array([[0., 1., 1., 1., 0., 0.],
[1., 0., 1., 1., 1., 1.],
[1., 1., 0., 1., 0., 1.],
[1., 1., 1., 0., 1., 1.],
[0., 1., 0., 1., 0., 1.],
[0., 1., 1., 1., 1., 0.]])
圖片。 在此處輸入圖像描述
情況 1. 在 y 方向平移 5 個單位。 連接矩陣。
array([[0., 1., 0., 1., 0., 1.],
[1., 0., 1., 1., 1., 0.],
[0., 1., 0., 1., 0., 1.],
[1., 1., 1., 0., 1., 1.],
[0., 1., 0., 1., 0., 1.],
[1., 0., 1., 1., 1., 0.]])
圖片。 在此處輸入圖像描述
知道為什么它們不同嗎?
連接矩陣是這樣計算的:
matrix = np.zeros((len(points),len(points))
for triangle in tri.simplices:
for i in range(4):
point_initial = triangulo[i]
point_final = triangulo[(i+1)%4]
if matrix[point_initial,point_final] == 1:
continue
matrix[point_initial,point_final] = 1
matrix[point_final,point_initial] = 1
你可以看到tri.simplices
在這兩種情況下也不同:
array([[1, 4, 3, 2],
[1, 4, 5, 2],
[1, 4, 5, 3],
[1, 0, 3, 2],
[1, 0, 5, 2],
[1, 0, 5, 3]], dtype=int32)
array([[1, 4, 3, 2],
[1, 4, 5, 2],
[1, 4, 5, 3],
[0, 1, 3, 2],
[0, 1, 5, 2],
[0, 1, 5, 3]], dtype=int32)
@geofisue 感謝您提出編寫答案的建議。
正如我在評論中所描述的,問題的原因是當從 2D 平面點過渡到 3D 實心點時,三角剖分中的單純形從三角形變為三角錐。
因此連接數從 3 變為 6。
然后我修改了計算連接矩陣的function,可以在nD中使用:
import itertools
matrix = np.zeros((len(points),len(points)))
for triangle in tri.simplices:
connections = list(itertools.combinations(triangle, 2))
for connection in connections:
point_initial = connection [0]
point_final = connection[1]
if matrix[point_initial,point_final] == 1:
continue
matrix[point_initial,point_final] = 1
matrix[point_final,point_initial] = 1
完整代碼:
import itertools
import numpy as np
from scipy.spatial import Delaunay
import matplotlib.pyplot as plt
points = np.array([ [-0.6, -0.1, -1.5], [0, 0, 0], [-1,-1,-1],[1, 0, 1], [1, 1, 2], [0, 1.1, -1]])
points_trans = points+[0,5,0] #for translation
tri = Delaunay(points)
tri_trans = Delaunay(points_trans)
def get_connection_matrix(points):
matrix = np.zeros((len(points),len(points)))
for triangle in tri.simplices:
connections = list(itertools.combinations(triangle, 2))
for connection in connections:
point_initial = connection [0]
point_final = connection[1]
if matrix[point_initial,point_final] == 1:
continue
matrix[point_initial,point_final] = 1
matrix[point_final,point_initial] = 1
return matrix
matrix = get_connection_matrix(points)
matrix_trans = get_connection_matrix(points_trans)
print(np.array_equal(matrix, matrix_trans))
結果:
> True
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.