Visualizing spherical harmonics in Python

前端 未结 2 609
醉酒成梦
醉酒成梦 2021-01-05 18:03

I am trying to draw a spherical harmonics for my college project. The following formula I want to depict,

Y = cos(theta)

for that, I wrote

相关标签:
2条回答
  • 2021-01-05 18:55

    The picture in the Wikipedia article Spherical harmonics is obtained by using the absolute value of a spherical harmonic as the r coordinate, and then coloring the surface according to the sign of the harmonic. Here is an approximation.

    x, y, z = sph2cart(np.abs(Y), phi, tta)
    
    fig = plt.figure()
    ax = fig.add_subplot( 111 , projection='3d')
    
    from matplotlib import cm
    ax.set_aspect('equal')
    ax.plot_surface(x, y, z, linewidth = 0.5, facecolors = cm.jet(Y), edgecolors = 'k')
    

    When you use Y itself as r, the two hemispheres (positive Y and negative Y) end up mapped onto the same half of the above surface.

    0 讨论(0)
  • 2021-01-05 18:59

    The Y you are passing to the function needs to be an absolute value to make it r, else z = cos(theta)^2 is always positive. If r is to be the radius then this what you should be doing.

    x, y, z = sph2cart(np.abs(Y), phi, tta)
    
    0 讨论(0)
提交回复
热议问题