python - How to rotate a 3D spot with numpy? -


i trying distribute spots on sphere. there's function define spot rho, theta, phi spherical coordinates:

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 , 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 

two sets of spots defined (s_t or s_p) varying theta or phi fixed value of rho:

#set of spots defined varying theta or phi s_t = np.asarray([make_spot_3d_spherical(1000,2, 30,t,0) 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) phi in [0,np.pi/6,np.pi/3,2*np.pi/3]]) 

then set of spots summed make 3d array containing different spots np.sum(s_t, axis =0) . 3d array projected along 1 of 3 axis:

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) 

finally, different projections displayed:

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() 

in resulting images,i waiting see spots distributed along circles, not case, when phi varies:

phi varies

or when theta varies:

enter image description here

thanks advices.

in function make_spot_3d_spherical got sin , cos mixed in definition of x0:

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

should be

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

now works. here's if vary phi:

s_p = np.asarray([make_spot_3d_spherical(1000,2, 30,0,phi) 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') 

enter image description here


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -