Random points on the surface of a sphere
Random points on the surface of a sphere
The latitude angle should have a PDF that follows a cosine curve from -π/2 to π/2.
In[]:=
Plot[Cos[x]/2,{x,-Pi/2,Pi/2}]
Out[]=
The CDF is the integral of the PDF .
In[]:=
Integrate[Cos[x]/2,x]
Out[]=
Sin[x]
2
Plot of the PDF with constant to make its range [0, 1).
In[]:=
Plot[(Sin[x]+1)/2,{x,-Pi/2,Pi/2}]
Out[]=
To generate latitude angles with this distribution, we need the inverse of the CDF.
In[]:=
Solve[y==(Sin[x]+1)/2,x]
Out[]=
x,x
Use the first of these to generate random (R, ϕ, θ) points. Because arcsine is an odd function, we can move the negative sign inside the function and set = 0.
c
1
In[]:=
n=5000;ϕ=ArcSin[2*RandomReal[1,n]-1];θ=RandomReal[{-Pi,Pi},n];R=5;
Convert to (x, y, z).
In[]:=
x=RCos[ϕ]Cos[θ];y=RCos[ϕ]Sin[θ];z=RSin[ϕ];pts=Transpose[{x,y,z}];
Plot the random points to see if they look uniformly distributed on the sphere’s surface.
In[]:=
ListPointPlot3D[pts,ViewPoint->{8,4,2},ViewVertical->{0,0,1},BoxRatios->{1,1,1},ImageSize->Medium,AxesOrigin->{0,0,0},Boxed->False,PlotRange->{{-6,6},{-6,6},{-6,6}},Ticks->None,AxesStyle->Directive[Black,AbsoluteThickness[1]]]
Out[]=
Another way to check the uniformity of the points on the surface is to estimate the moments of inertia of the thin-walled spherical shell— , , and —via Monte Carlo integration and compare that to the analytical solution. Assume unit density of the material.
I
xx
I
yy
I
zz
In[]:=
ixxEstimate=(4PiR^2/n)Total[y^2+z^2]
Out[]=
5203.65
In[]:=
iyyEstimate=(4PiR^2/n)Total[x^2+z^2]
Out[]=
5226.96
In[]:=
izzEstimate=(4PiR^2/n)Total[x^2+y^2]
Out[]=
5277.35
In[]:=
iAnalytical=8/3PiR^4//N
Out[]=
5235.99
In[]:=
ixxEstimate/iAnalytical
Out[]=
0.993824
In[]:=
iyyEstimate/iAnalytical
Out[]=
0.998277
In[]:=
izzEstimate/iAnalytical
Out[]=
1.0079