
Generating uniformly random distribution of points inside a sphere

sjr51
//// @param num number of points to be generated //// @param Radius radius of sphere Function UniformSphere(num,Radius) Variable num,Radius Make/O/N=(num) xw,yw,zw Variable phi,theta,rr Variable i for(i = 0; i < num; i += 1) phi = pi + enoise(pi) theta = acos(enoise(1)) rr = Radius * ((0.5 + enoise(0.5))^(1/3)) xw[i] = rr * sin(theta) * cos(phi) yw[i] = rr * sin(theta) * sin(phi) zw[i] = rr * cos(theta) endfor DoWindow/K xyPlot Display/N=xyPlot yw vs xw ModifyGraph/W=xyPlot mode=3,marker=8 ModifyGraph/W=xyPlot width={Plan,1,bottom,left} DoWindow/K yzPlot Display/N=yzPlot zw vs yw ModifyGraph/W=yzPlot mode=3,marker=8 ModifyGraph/W=yzPlot width={Plan,1,bottom,left} DoWindow/K xzPlot Display/N=xzPlot zw vs xw ModifyGraph/W=xzPlot mode=3,marker=8 ModifyGraph/W=xzPlot width={Plan,1,bottom,left} End

Forum

Support

Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
Also, to visualize the distribution why not display it in Gizmo:
Depending on the number of points you may want to either display them as a cloud or simply reduce the radius:
May 31, 2016 at 08:47 am - Permalink