Re: Random spherical troubles
- To: mathgroup at smc.vnet.net
- Subject: [mg25199] Re: Random spherical troubles
- From: dkeith at sarif.com
- Date: Tue, 12 Sep 2000 21:24:44 -0400 (EDT)
- References: <8pkl8u$m80@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hello Barbara, Your problem is similar to others I have considered doing Monte Carlo simulations. I think it can be understood best in two steps: 1) You want the probability of a point occuring in the region dTheta*dPhi to be proportional to the actual Euclidean area on the surface of the sphere represented by dTheta*dPhi. But that area is not just that product. If you condsider how Euclidean area is swept out by theta and phi, in just the same way you would use to integrate the surface, you will see that dArea is given by r^2*Sin[theta] *dTheta*dPhi. So the probability of finding a point in dTheta*dPhi is proportional to r^2*Sin[theta]. 2) The next problem is to create a transformation which takes a random variable distribution we have into this one we want. There is a nice theory in probability that says if p[x] is a distribution function and f[x] is its cumulative distribution (integral), and the distribution p is normalized, then Inverse[f][Random[0,1]] is a variable having p distribution. (Random[0,1] is a random variable of uniform distibution in (0,1).) So to make use of this we take f[theta] to be A*Sin[theta] since we need probability proportional to Sin[theta] and independent of phi. "A" is for normalization. The cumulative distribution is gotten by integrating and normalizing to get f[theta]=(1-Cos[theta])/2. The transformation is then the inverse function theta=ArcCos[1-2*f]. So our new random variable can be generated as {r, theta, phi}={r, ArcCos[1-2 Random[]],Random[Real,{0,2Pi}]} or for example polarPoints = Table[{1, ArcCos[1 - 2Random[]], Random[Real, {0, 2Pi}]}, {1000}]; Regards, David In article <8pkl8u$m80 at smc.vnet.net>, Barbara DaVinci <barbara_79_f at yahoo.it> wrote: > Hi MathGrouppisti > > This time, my problem is to generate a set of > directions randomly > distributed over the whole solid angle. > > This simple approach is incorrect (spherical > coordinates are assumed) : > > Table[{Pi Random[], 2 Pi Random[]} , {100}] > > because this way we obtain a set of point uniformly > distributed > over the [0 Pi] x [0 2Pi] rectangle NOT over a > spherical surface :-( > > If you try doing so and plot the points {1, > random_theta , random_phi} > you will see them gathering around the poles because > that simple > transformation from rectangle to sphere isn't > "area-preserving" . > > Such a set is involved in a simulation in statistical > mechanics ... > and I can't get out this trouble. > > May be mapping [0 Pi] x [0 2Pi] in itself , using an > suitable > "non-identity" transformation, can spread points in a > way balancing > the poles clustering effect. > > ==================================================================== > > While I was brooding over that, an intuition flashed > trought my mind : > since spherical to cartesian transformation is > > x = rho Sin[ theta ] Cos[ phi ] > y = rho Sin[ theta ] Sin[ phi ] > z = rho Cos[ theta ] > > perhaps the right quantities to randomly spread > around are Cos[ theta ] and > Cos[ phi ] rather than theta and phi for itself. Give > a glance at this : > > Table[{ > ArcCos[ Random[] ], > ArcCos[ Random[] Sign[ 0.5 - Random[] ] > } , {100}] > > Do you think it is close to the right ? Do you see a > better way ? > Have you just done the job in the past ? Should I > reinvent the wheel ? > > ==================================================================== > > I thanks you all for prior replies and in advance > this time. > > Distinti Saluti > (read : "Faithfully yours") > > Barbara Da Vinci > barbara_79_f at yahoo.it > > ______________________________________________________________________ > Do You Yahoo!? > Il tuo indirizzo gratis e per sempre @yahoo.it su http://mail.yahoo.it > > Sent via Deja.com http://www.deja.com/ Before you buy.