【发布时间】:2015-07-07 16:41:08
【问题描述】:
我正在尝试在球体上分布点。有一个函数可以用 rho, theta, phi 的球坐标定义一个点:
def make_spot_3d_spherical(bright, spread, rho, theta, phi):
x0 = int(rho*np.sin(theta)*np.cos(phi))
y0 = int(rho*np.sin(theta)*np.sin(phi))
z0 = int(rho*np.cos(phi))
# Create x and y indices
x = np.linspace(-50, 50, 200)
y = np.linspace(-50, 50, 200)
z = np.linspace(-50, 50, 200)
X, Y, Z = np.meshgrid(x, y, z)
Intensity = np.uint16(bright*np.exp(-((X-x0)/spread)**2
-((Y-y0)/spread)**2
-((Z-z0)/spread)**2))
return Intensity
通过改变 rho 的固定值的 theta 或 phi 来定义两组点(S_t 或 S_p):
#set of Spots defined by varying theta or phi
S_t = np.asarray([make_spot_3d_spherical(1000,2, 30,t,0) for t in [0,np.pi/6,np.pi/3,2*np.pi/3]])
S_p = np.asarray([make_spot_3d_spherical(1000,2, 30,0,phi) for phi in [0,np.pi/6,np.pi/3,2*np.pi/3]])
然后将这组点相加,形成一个 3D 数组,其中包含 np.sum(S_t, axis =0) 的不同点。然后沿三个轴之一投影 3D 数组:
set_of_St0 = np.sum(np.sum(S_t, axis =0), axis = 0)
set_of_St1 = np.sum(np.sum(S_t, axis =0), axis = 1)
set_of_St2 = np.sum(np.sum(S_t, axis =0), axis = 2)
set_of_Sp0 = np.sum(np.sum(S_p, axis =0), axis = 0)
set_of_Sp1 = np.sum(np.sum(S_p, axis =0), axis = 1)
set_of_Sp2 = np.sum(np.sum(S_p, axis =0), axis = 2)
最后显示不同的投影:
plt.subplot(131, xticks=[], yticks=[])
plt.imshow(set_of_Sp0, interpolation = 'nearest')
plt.subplot(132, xticks=[], yticks=[])
plt.imshow(set_of_Sp1, interpolation = 'nearest')
plt.subplot(133, xticks=[], yticks=[])
plt.imshow(set_of_Sp2, interpolation = 'nearest')
plt.show()
在生成的图像中,我正在等待查看沿某些圆圈分布的斑点,但当 phi 变化时,情况并非如此:
或者当 theta 变化时:
感谢您的建议。
【问题讨论】:
标签: python numpy 3d coordinates polar-coordinates