in reply to Re: computational efficiency in thread computational efficiency
I've read the article a couple of times by now. Let me comment on that. I've been planning to randomize my rotation subroutine by doing three subsequent arbitrary rotations about each axis in cartesian space, i.e. arbitrary rotation with independent randomization for each axis x, y and z. These however have to be randomized by two randomization processes each, as the sign of the cosine corresponding to the randomized sine has to randomized, too (if I'm not mistaken here, cf. my reply to moritz comment on correctness). Hence, my (thanks to your comments) improved idea would involve six randomizations for each arbitrary rotation, while the method posted on wolfram would involve only two (cf. equations 9 to 11 in the article), correct?
What I'm asking myself right now is the following: Moritz is absolutely correct, as a single rotation about one axis (which was my original question) results in omitting half of the angles, consequently incompleteness and bias towards rotation angles below 180°. Would this still be true, if the routine is applied about each axis xyz? So, if Marsaglia (1972) uses two randomizations to produce an arbitrary point in three dimensional space in the polar coordinate system, would three randomizations in cartesian space still result in incompleteness? I think so, because equations 13 to 15 imply, that at least four randomizations are needed in cartesian space... ?
P.S.: MidLifeXis: Thank you, I found use Benchmark qw(:all) ;on http://perldoc.perl.org/Benchmark.html
Re^3: computational efficiency by Lotus1 (Deacon) on Oct 12, 2011 at 18:53 UTC 
The approach I like for this problem is what Perlbotics suggested. Make a table. I suggest a hash of arrays where the keys are angles and each value is an array of sin and cos values. Then you choose a random angle (0360) and get both sin and cos from a fast hash with the negative signs included. This takes care of all four quadrands.
Do this for each axis of rotation as you proposed. The article I posted was about picking uniformly distributed points on the surface of a sphere which I believe is more difficult than your problem. The only point I was making with my previous post is that if you pick random sine values the corresponding angles are not uniformly distributed. I'm not sure about proving this approach of three rotations but it seems good to me. I'll think about it more and maybe I'll come up with a proof.
use warnings;
use strict;
my $ref_trig = make_trigtable();
print "\nangle sine cosine\n";
foreach (1..15) {
my $angle = sprintf "%.1f", rand(3600)/10;
printf "%5.1f %8.5f %8.5f\n", $angle, $ref_trig>{$angle}[0], $ref
+_trig>{$angle}[0];
}
sub make_trigtable {
use constant PI => 4 * atan2(1, 1);
use constant DEG_TO_RAD => PI / 180;
my %trig;
foreach (0..3600) {
my $angle = sprintf "%.1f", $_/10;
$trig{$angle}=[sin $angle * DEG_TO_RAD, cos $angle * DEG_TO_RA
+D];
}
return \%trig;
}
__END__
C:\perlmonks>perl sinhash.pl
angle sine cosine
216.2 0.59061 0.59061
268.6 0.99970 0.99970
166.8 0.22835 0.22835
276.8 0.99297 0.99297
81.6 0.98927 0.98927
355.4 0.08020 0.08020
11.9 0.20620 0.20620
82.3 0.99098 0.99098
70.1 0.94029 0.94029
173.1 0.12014 0.12014
14.5 0.25038 0.25038
251.3 0.94721 0.94721
161.6 0.31565 0.31565
117.7 0.88539 0.88539
319.7 0.64679 0.64679
 [reply] [d/l] 
