【问题标题】:How to rotate a 3D spot with numpy?如何用 numpy 旋转 3D 点?
【发布时间】: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


    【解决方案1】:

    在函数 make_spot_3d_spherical 中,sincos 混淆了 x0 的定义:

    x0 = int(rho*np.sin(theta)*np.cos(phi))
    

    应该是

    x0 = int(rho*np.cos(theta)*np.sin(phi))
    

    现在可以了。如果你改变phi

    S_p = np.asarray([make_spot_3d_spherical(1000,2, 30,0,phi) for phi in np.linspace(0, 2*np.pi, 20)])
    set_of_Sp0 = np.sum(np.sum(S_p, axis =0), axis = 0)
    plt.imshow(set_of_Sp0, interpolation = 'nearest')
    

    【讨论】:

      猜你喜欢
      • 2019-11-19
      • 1970-01-01
      • 1970-01-01
      • 2021-10-28
      • 2014-12-26
      • 1970-01-01
      • 2019-01-27
      • 2017-08-28
      • 1970-01-01
      相关资源
      最近更新 更多