Alan2,
I tried your method of modifying a uniform angle distribution according to the "rectangle size", though the results I got some strange results. (see projections onto orthogonal planes - attached)
I'm using Matlab and my code is
for polang=-pi:AngSpace:pi
for u=-1:USpace:1
azang=acos(u);
xmag=sin(polang)*cos(azang);
ymag=sin(polang)*sin(azang);
zmag=cos(polang);
if xmag>0.5
Dist=1000/xmag;
ypos=floor(2000+Dist*ymag);
zpos=floor(2000+Dist*zmag);
Imx(ypos,zpos)=Imx(ypos,zpos)+1;
end
if ymag>0.5
Dist=1000/ymag;
xpos=floor(2000+Dist*xmag);
zpos=floor(2000+Dist*zmag);
Imy(xpos,zpos)=Imy(xpos,zpos)+1;
end
if zmag>0.5
Dist=1000/zmag;
xpos=floor(2000+Dist*xmag);
ypos=floor(2000+Dist*ymag);
Imz(xpos,ypos)=Imz(xpos,ypos)+1;
end
end
end
Thanks
Rich
alan2 said:
I forgot about this thread. I apologize for answering as if you were solving an exact geometric problem. For your problem I would still use spherical coordinates. To make it easy, suppose your radius is 1. Let θ=polar angle, ∅=azimuthal angle. Your problem in using uniformly generated random numbers is that the area of the infinitesimal "rectangle" on the surface defined by the changes dθ and d∅ is given by dA=sin∅d∅dθ. So if you randomly choose θ and ∅ you end up with concentrations of points inversely proportional to the area and thus more points concentrated near the poles in the "smaller rectangles". So you need to pick random numbers proportional to the size of the rectangles, i.e. generate random numbers proportional to sin∅. The cumulative distribution of sin∅ is F(∅)=1-cos∅. So you choose a random number u from a uniform distribution on [0,1] and find the inverse ∅=arccos(1-u). The resulting ∅ are random numbers distributed like sin∅. These ∅ should be uniformly distibuted on the sphere.
You can work out the details. You have an issue with the bottom half of the sphere because the range of arccos and the range of ∅ are different but you can take care of that easily. Check to make sure the distribution is normalized, etc. Try it, it should work.