【发布时间】:2020-01-21 00:15:17
【问题描述】:
我有一个由均匀分布的 xyz 笛卡尔点组成的大型 3D 网格(约 800,000 点),我想根据占据球体的点数找到球体内部的体积。我目前正在使用 scipy cKDTree 并使用 query_ball_point 检测原点(0,0,0)一定半径内的所有点来估计体积,但这个体积(grid_vol,下面)通常有很大不同(50% 错误或更大) 比真实体积 (sphere_vol)。
import numpy as np
from scipy import spatial
import math
#constants
xl = -3.15
xr = 1.75
yl = -2.0
yr = 2.0
zl = -1.15
zr = 3.9
spacing = 0.05
R = 3.5
cube = spacing ** 3
#Create grid
x=np.arange(xl,xr,spacing)
y=np.arange(yl,yr,spacing)
z=np.arange(zl,zr,spacing)
x2,y2,z2=np.meshgrid(x,y,z,indexing='ij')
all_grid=np.array([x2.flatten(),y2.flatten(),z2.flatten()]).T
cube = spacing ** 3
point_tree = spatial.cKDTree(all_grid) # allgrid = evenly spaced rectangular grid
n_voxel = len(point_tree.query_ball_point((0,0,0), R)) # number of points in grid occupying sphere of radius R
grid_vol = n_voxel * cube # volume based on grid points
sphere_vol = 4 / 3 * math.pi * R ** 3 # vol of sphere w/ radius R to compare
在这种情况下:
grid_vol = 78.1275
sphere_vol = 179.5944
我想知道是否有一个已知的模块可以很好地用于从网格点测量球体的这种应用
【问题讨论】:
-
“非常不同”是什么意思?多少钱?从连续空间到体素化空间时,您总是会丢失信息
-
试图将错误减少 50% 或更多