Followings are the program for random walk on unit sphere sphere. The key part is the definition of a function whose name is rotateWithAxis. The function returns the list (3D unit vector) q which derived a rotation of the point vector p on the unit sphere with the axis a. The third argument theta is the angle of counter clockwise rotation.
rotateWithAxis[p_, a_, theta_] := #/Norm[#] &@((1 – Cos[theta]) (a.p) a + p Cos[theta] + Cross[a, p] Sin[theta]);
Using the function, the random walk on a unit sphere is written as follows:
rw = With[{stepLength = 0.03, num = 10000},
Module[{rotateWithAxis, p, a, q},
rotateWithAxis[p_, a_, theta_] := #/Norm[#] &@((1 – Cos[theta]) (a.p) a + p Cos[theta] + Cross[a, p] Sin[theta]);
a = {1., 0, 0};
q = {Cos[stepLength], Sin[stepLength], 0};
Table[ p = a; a = q; q = rotateWithAxis[p, a, RandomReal[{0, 2 Pi}]], {num}]
]
];
The result can be displayed using Graphics3D like,
Graphics3D[Line[rw], Boxed -> False]
The following image is one of the resultant of this program.
Post a Comment