POV-Ray : Newsgroups : povray.general : vrotate? : Re: vrotate? Server Time
30 Jul 2024 16:18:44 EDT (-0400)
  Re: vrotate?  
From: clipka
Date: 8 Mar 2009 10:50:01
Message: <web.49b3dad1ed80e874a745f7570@news.povray.org>
"Kenneth" <kdw### [at] earthlinknet> wrote:
> Ugh. VCross, vdot...my head spins.  I'm still having trouble wrapping my poor
> little mind around the transform.inc stuff in general; just spent (another!)
> hour or two poring over it all. I try mightily to use some of those macros in
> my code, only to find that my understanding of their workings is just plain
> wrong, or else I'm not setting them up correctly. Someday it all *will* infuse
> my brain cells...
>
> An example (which I'm trying to figure out at the moment): making my translated
> camera rotate or 'roll' (like the 'rolling' of an airplane, if I have the
> analogy correct), around the axis defined by/between the arbitrary camera
> position and its look_at point. (So that the rolling axis is 'centered' in the
> camera lens, so to speak.)  I *know* it should be simple to do, but right now
> it's a mystery wrapped in an enigma.

I know this feeling. Luckily, I have come to a point where, when I *do* take
time to think about it, I ultimately come up with something that does the job.
However, unless I really *need* to, I prefer not to bother my brains with these
things. It feels like I need to re-route half of my synapses each time :P

As a matter of fact, "rolling" some object is not so trivial as it may seem at
first, as the only rotational operations POV provides (including the macros in
"translations.h") are rotations about the main axes.

So here's how to do it:

- Calculate a transformation M that will get your object from its current
orientation to one that will align its axis of rotation to, say, z. This is the
trickiest part.

- Apply the following transofrmations:

    tramsform { M }
    rotate z*alpha
    transform { M inverse }

To get the transformation M, you need to first rotate the object about the y
axis to re-orient the intended axis of rotation to somewhere in the yz plane,
then rotate the object about the x axis to re-orient it to the z axis.

To find out how you need to rotate about the y axis, you have to imagine looking
at it from straight above, i.e. ignore the y components of the vector:

    #local yAngle = VRotation(<1,0,1>*myAxis, z, y);
    #local myAxis2 = VRotate(myAxis, y*yAngle);

Now that you know where your axis will end up after rotating about y, you can
find out how to re-orient it to match the z axis:

    #local xAngle = VRotation(myAxis2, x, z);
    #local M = transform {
      rotate y * yAngle
      rotate x * xAngle
    }


Some things to keep in mind when working with vectors and transformations:

- VDot and VCross are your friends. Get to know them, and find out how to make
best use of them.

- Quite a lot of tasks are a good deal easier if you consider a 2D projection of
the thing first, then deal with the third dimension separately.

- Watch out for extreme situations; e.g. the above math will fail if the axis
you intend to rotate about happens to be the y axis.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.