Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

One suggestion. It appears as though you may be rotating your points multiple times; and doing so by modifying the original coordinates by each rotation. The problem with this is that as the rotations accumulate, the rounding errors inevitably introduced by each successive rotation also accumulate, but those rounding errors will be different and accumulate differently for each point on the structure being rotated. The net affect is that after many small rotations, the registration between the points making up the structure will wander.

A concrete example might clarify here. Let's say you start with a nice unit vector cube distributed equidistant around the origin:

my $cube = [ [-0.5, 0.5, 0.5],[ 0.5, 0.5, 0.5],[ 0.5,-0.5, 0.5],[-0.5,-0.5, 0.5 +], # front face [-0.5, 0.5,-0.5],[ 0.5, 0.5,-0.5],[ 0.5,-0.5,-0.5],[-0.5,-0.5,-0.5 +], # back face ];

After rotating 360° around each axis in 1° steps -- 1080 floating point calculations, you will likely end up with values that look more like:

[ [-0.50000000000000011, 0.49999999999999989, 0.49999999999999971], [ 0.50000000000000011, 0.500000000023, 0.499999999987873], [ 0.50000000000000011,-0.49999999999445, 0.5000000000123], [-0.49999999999999576,-0.49999999999999989, 0.500000000000876], # +front face [-0.500000000000001, 0.49999999999999989,-0.49999999999999987], [ 0.50000000000000011, 0.500000000000000345,-0.500000000000000234] +, [ 0.49999999999999921,-0.500000000000000001,-0.500000000000000022] +, [-0.50000000000000011,-0.4999999999999999002,-0.50000000000000001] +, # back face ];

As you can see, the 'cube' has become irrevocably distorted. And that was starting with relatively large (compared to your atomic scale measurements) and floating point friendly (0.5 stored exactly as a FP number) values. With smaller values and values that cannot be exactly represented, the distortions are going to be even more noticeable.

An oft-used alternative is to retain the original coordinates and accumulate the rotations -- usually in the form of a transform matrix -- and only apply the rotations when fixing a position for output (eg. when displaying).

In this way, the you only have the distortions from a single calculations rounding errors at any given position, rather than the accumulated distortions of many calculations.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

In reply to Re: Rotation around an axis clockwise and anti-clockwise algorithm question? by BrowserUk
in thread Rotation around an axis clockwise and anti-clockwise algorithm question? by fraizerangus

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [choroba]: Not sure what meteorological event it's been, but it's -6 now and lots of snow around.
    [Discipulus]: if so is not buran; it's the putin's revenge.. ;=)

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (4)
    As of 2018-03-19 08:10 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (236 votes). Check out past polls.