POV-Ray : Newsgroups : povray.general : computed rotate in macros : Re: computed rotate in macros Server Time
12 Aug 2024 09:18:00 EDT (-0400)
  Re: computed rotate in macros  
From: John M  Dlugosz
Date: 1 Mar 1999 19:42:59
Message: <36db3413.0@news.povray.org>
A matrix does any kind of linear transform.  Rotate is one such transform.
Every rotate, translate, or shear is represeted as a matrix.  A point is
represented as a vector.  To transform the point, multiply the point by the
matrix.  To do two things, say a rotate followed by another rotate, multiply
the point by the first matrix, then multiply the result by the second
matrix.  IOW,
    result= p * M1 * M2;
Now it happens that you can also multiply the two matrices together, which
creates a single matrix that does the same thing!  IOW,
    result= p * (M1*M2);
the multiplication is associative.  (Note that it is not commutative,
though).
So you could write:
    matrix M3= M1*M2;
    result= p*M3;
and get the same answer, and reuse M3 many times with less work.

So in my notes, M.rotate is just a function that changes M to be whatever it
was before and the desired rotation on top of that.

Something like this:

    void matrix::rotate (const vector& input)
    {
    matrix rotX= (
        1,    0,    0,
        0,    cos(deg_to_rad(input.x)),    sin(deg_to_rad(input.x)),
        0,    -sin(deg_to_rad(input.x)),    cos(deg_to_rad(input.x))    );
    matrix rotY=  /// similar logic
    matrix rotZ= /// similar logic -- look it up in a Linear Algebra book.
    (*this) = (*this) * rotX * rotY * rotZ;
    }

This takes a vector holding separate x, y, and z angles in degrees, and
folds them into the original matrix.

--John



Spider wrote in message <36DACFFA.B2203C07@bahnhof.se>...
>I can't say I understand this. some more explination please.
>As you do it, I get that M is anew matrix pointer at I, then you apply a
rotate
>to a matrix ???? Hmm, don't get that at all.
>
>"John M. Dlugosz" wrote:
>>
>>
>> It sure is.  I don't know if it's worth doing it in POV script, though.
>> It's not exactly an object-oriented language.
>>
>>     matrix M= I;  // identity matrix
>>     M.rotate (n*x);
>>     M.rotate (n*y);
>>     M.rotate (n*z);
>>     M.translate (whatever);
>>     // ... later
>>     someObject.rotate (M);  // do the whole thing as one step
>>     anotherObject.rotate (M);  // same value used here.
>>
>> --John
>
>--
>//Spider
>( spi### [at] bahnhofse ) [ http://www.bahnhof.se/~spider/ ]
>#declare life = rand(seed(42))*sqrt(-1);


Post a reply to this message

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