The spherical coordinates are (r, theta, phi). And the distribution is given below.

enter image description here

enter image description here

To generate the position, I'm using inverse transform sampling, and for plotting I'm transforming them in (X, Y, Z) coordinate. I was expecting to see dots spreaded over a hollow sphere, but something bizarre is coming. And I couldn't figure out what is the problem. Here is the Matlab code

K=200; 
u=rand([1 K]);
phi_array=2*pi.*u;          
theta_array=acos(1-2.*u);

R_M=160;
R_m=10;
r_k= (R_m^3+(R_M^3-R_m^3).*u).^(1/3);
X=r_k .* cos(phi_array) .* sin(theta_array);
Y=r_k .* sin(phi_array) .* sin(theta_array);
Z=r_k .* cos(theta_array);
scatter3(X,Y,Z);

And here is the plot of this file enter image description here

Can you help me to point out what is wrong in my code? Theoretically, I know there is not any problem but don't know what's causing the error. I know there are other ways to generate these locations, but I'm interested to know what's the problem in my code.

0

There are 0 best solutions below