Python:用球体填充长方体

时间:2014-04-09 05:56:53

标签: python comparison imaging

我想知道如何在长方体中创建球体。这个长方体(50,50,50)被许多点包围,我想要的是获得点位置及其在球体内的值(半径= 2)。

任何想法/建议/代码/信息都非常感谢..

1 个答案:

答案 0 :(得分:1)

创建一个球体,其中心(i,j,k)和长方体(x0,y0,z0):

points_in_sphere = (x0 - i)**2 + (y0 - j)**2 + (z0 - k)**2 <= (radius)**2

提取点的坐标:

x1,y1,z1 = np.argwhere(points_sphere)[:,0], np.argwhere(points_sphere)[:,1], np.argwhere(points_sphere)[:,2]

打印点值:

print cubiod[x1,y1,z1]