       Re: Random spherical troubles

• To: mathgroup at smc.vnet.net
• Subject: [mg25218] Re: [mg25170] Random spherical troubles
• From: Tomas Garza <tgarza01 at prodigy.net.mx>
• Date: Fri, 15 Sep 2000 02:21:51 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Your question has certainly attracted quite a number of solutions. IMHO,
I think Daniel Lichtblau (in his (i)) and Ranko Bojanic offer the more
straightforward. I assume that "randomly distributed over the whole
solid angle" means that they obey a uniform distribution in three
dimensions. It is clear that the line going from the origin to the point
in three dimensions generated by {Random[], Random[], Random[]} is then
(pseudo) randomly distributed inside the first octant. The following
code will generate 100 (pseudo) randomly directed lines from the origin.
It will show a scatter plot of such lines in 3D, where the points in red
lie on the unit sphere and have the same direction as the corresponding
points in blue directly generated by three randomly chosen coordinates
(you needn't discard those points originally lying outside the unit
sphere, as Daniel suggests).

<< Graphics`Graphics3D`;
long[x_] := Sqrt[x.x];
n = 100;
points3D = Table[{Random[], Random[], Random[]}, {n}];
a13D = ScatterPlot3D[points3D, PlotStyle -> {Hue[0.75],
PointSize[0.015]},
DisplayFunction -> Identity];
points3D2 =
Table[points3D[[j]]/Sqrt[points3D[[j]].points3D[[j]]], {j, 1,
Length[points3D]}];
a23D = ScatterPlot3D[points3D2, PlotStyle -> {Hue,
PointSize[0.015]},
DisplayFunction -> Identity];
comp = Table[
Max[long[points3D[[j]]], long[points3D2[[j]]]], {j, 1,
Length[points3D]}];
linas3D =
Show[Table[
Graphics3D[
Line[{{0, 0, 0},
If[comp[[j]] <= 1, {points3D2[[j, 1]], points3D2[[j,
2]],
points3D2[[j, 3]]}, {points3D[[j, 1]], points3D[[j,
2]],
points3D[[j, 3]]}]}]], {j, 1, Length[points3D]}],
DisplayFunction -> Identity];
Show[a13D, a23D, linas3D, Axes -> True, PlotRange -> {{0, 1}, {0, 1},
{0, 1}},
DisplayFunction -> \$DisplayFunction];

The plot is somewhat deceiving in that the resulting lines look not
quite so random. However, if you try different 3D ViewPoints you'll be
satisfied that they are all right. And if you look at the 2D projections
of the red points (i.e., those lying on the unit sphere) on each of the
orthogonal planes, you'll see that they are indeed behaving reasonably
well, as far as one can judge simply by looking at them. For example:

In:=
proy = points3D2 /. {x_, y_, z_} -> {x, z};
In:=
b = ListPlot[proy, PlotStyle -> {Hue, PointSize[0.015]},
PlotRange -> {{0, 1}, {0, 1}}, DisplayFunction -> Identity];
In:=
Show[Graphics[Circle[{0, 0}, 1, {0, Pi/2}]], b, Axes -> True,
AspectRatio -> 1]

Tomas Garza
Mexico City

Barbara DaVinci wrote:
.....
>  This time, my problem is to generate a set of
> directions randomly
>  distributed over the whole solid angle.
.....

```

• Prev by Date: Re: Re: Mathematica Publication Question
• Next by Date: Re: Service multiple mathlinks
• Previous by thread: RE: Random spherical troubles
• Next by thread: Re: Random spherical troubles