jishnub / SphericalHarmonics.jl

Associated Legendre Polynomials and Spherical Harmonics in Julia
MIT License
10 stars 1 forks source link

Why are my spherical harmonics plots not matching with scipy? #94

Closed ipcamit closed 2 years ago

ipcamit commented 2 years ago

Consider the following attempt to plot $Y_{1,0}$

begin
    θ = collect(0:0.1:2π+0.1)
    ϕ = collect(0:0.05:π+0.05)
    x = zeros(64, 64)
    y = zeros(64, 64)
    z = zeros(64, 64)
    f = zeros(64, 64)
    for i = 1:64
        for j = 1:64
            Y = computeYlm(θ[i],ϕ[j],lmax=1)
            f[i, j] = abs(Y[(1,0)])
            r = f[i, j]
            x[i, j] = r*sin(ϕ[i])*cos(θ[j])
            y[i, j] = r*sin(ϕ[i])*sin(θ[j])
            z[i, j] = r*cos(ϕ[i])
        end
    end
end

It yields the following plot: newplot

compare it with equivalent scipy sph_harm plot,

theta = np.linspace(0,2*np.pi,100)
phi = np.linspace(0,np.pi,100)
x = np.zeros((100,100))
y = np.zeros((100,100))
z = np.zeros((100,100))
f = np.zeros((100,100))
for i in range(100):
    for j in range(100):
        Y10 = sph_harm(0,1,theta[j],phi[i])
        f[i,j] = np.abs(Y10)
        r = f[i,j]
        x[i,j] = r*np.sin(phi[i])*np.cos(theta[j])
        y[i,j] = r*np.sin(phi[i])*np.sin(theta[j])
        z[i,j] = r*np.cos(phi[i])

Figure17

What I am doing wrong here?

ipcamit commented 2 years ago

Sorry, I got confused between theta and phi angles. apparently they are opposite in mathematics and chemisty