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 (0-360) 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

In reply to Re^3: computational efficiency by Lotus1
in thread computational efficiency by thelycaeum

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.