Visualizing spherical harmonics in Python

前端 未结 2 608
醉酒成梦
醉酒成梦 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.

提交回复
热议问题