POV-Ray : Newsgroups : povray.general : Convert 313 Cartesian Euler Angles to POV-Ray Coordinates : Re: Convert 313 Cartesian Euler Angles to POV-Ray Coordinates Server Time
3 Oct 2022 17:19:22 EDT (-0400)
  Re: Convert 313 Cartesian Euler Angles to POV-Ray Coordinates  
From: Tor Olav Kristensen
Date: 19 Sep 2022 14:30:00
Message: <web.6328b4b97d53bcdae12da8f789db30a9@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> "LAP" <nomail@nomail> wrote:
> > I am attempting to use POV-Ray for rigid-body dynamics.
> >
> > I have software that produces rotation parameters as 313 Euler angles, psi,
> > theta, and phi, and the associated 313 rotation matrix.  All this is done in 3D
> > Euclidean (Cartesian) space.
> >
> > The problem I face is converting these Euclidean 313 parameters to work in
> > POV-Ray coordinates.  In other words, I need to convert the Euclidean rotation
> > matrix to a POV-Ray matrix so that I can propery rotate objects (and their
> > textures).
> >
> > Since the basic coordinate transform is <x,y,z> Euclidean to <-z, x, y> I have
> > tried to rearrange the components of the Euclidean 313 rotation matrix to
> > duplicate this transform but the results are not correct.
> >
> > Given a rotation matrix in 3D Euclidean space:
> >
> > | 00 01 02 |
> > | 10 11 12 |
> > | 20 21 22 |
> >
> > What is the correct way of transforming this matrix so that it will rotate a
> > POV-Ray object in the same way?
>
> Hi
>
> You may want to have a look at the code below.
>...

In these expressions:

M_Mult(MM_0R, MM_Rot_313_a) and M_Mult(MM_0R, MM_Rot_313_b)

- in the code in my reply above, row vectors was multiplied by "313" rotation
matrices.

The code below shows how one can multiply the transposed of the "313" rotation
matrices with column vectors to achieve the same results (except that the
vectors are now column vectors instead of row vectors).

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.7;

#include "vectors.inc"
#include "matrices.inc"

global_settings { assumed_gamma 1.0 }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#macro PrintVector3D(v0)

    #debug concat("<", vstr(3, v0, ", ", 0, -1), ">")

#end // macro PrintVector3D

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#debug "\n\n"

#declare v0 = <+3, -4, +2>;
#debug "v0 = \n"
PrintVector3D(v0)
#debug "\n\n"

#declare MM_0C = M_Col_FromDir3D(v0);
#debug "MM_0C = \n"
M_Print(MM_0C)
#debug "\n\n"

#declare Psi = +30;
#declare Theta = -45;
#declare Phi = +15;

#declare vR =
    vrotate(
        vrotate(
            vrotate(
                v0,
                Psi*z
            ),
            Theta*x
        ),
        Phi*z
    )
;
#debug "vR = \n"
PrintVector3D(vR)
#debug "\n\n"


#declare Transform_313 =
    transform {
        rotate Psi*z
        rotate Theta*x
        rotate Phi*z
    }

#declare vT = VectorTransform(v0, Transform_313);
#debug "vT = \n"
PrintVector3D(vT)
#debug "\n\n"

#declare MM_Rot_313_a = M_FromTransform(Transform_313);
#debug "MM_Rot_313_a = \n"
M_Print(MM_Rot_313_a)
#debug "\n\n"

#declare MM_R_a = M_Mult(M_Transpose(MM_Rot_313_a), MM_0C);  // <--- NB!
#debug "MM_R_a = \n"
M_Print(MM_R_a)
#debug "\n\n"

#declare MM_Rot_Psi = M_Rotate3D_AroundZ(radians(Psi));  // 3
#declare MM_Rot_Theta = M_Rotate3D_AroundX(radians(Theta));  // 1
#declare MM_Rot_Phi = M_Rotate3D_AroundZ(radians(Phi));  // 3

#declare MM_Rot_313_b =
    M_Mult(
        M_Mult(
            MM_Rot_Psi,
            MM_Rot_Theta
        ),
        MM_Rot_Phi
    )
;
#debug "MM_Rot_313_b = \n"
M_Print(MM_Rot_313_b)
#debug "\n\n"

#declare MM_R_b = M_Mult(M_Transpose(MM_Rot_313_b), MM_0C);  // <--- NB!
#debug "MM_R_b = \n"
M_Print(MM_R_b)
#debug "\n\n"

#error "No error, just finished!"

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

The result from running the code above:

v0 =
<3.000000, -4.000000, 2.000000>

MM_0C =
array[4][1] {
    {  3.000000 },
    { -4.000000 },
    {  2.000000 },
    {  0.000000 }
}

vR =
<4.434831, 1.214589, 2.803043>

vT =
<4.434831, 1.214589, 2.803043>

MM_Rot_313_a =
array[4][4] {
    {  0.745010,  0.565650, -0.353553,  0.000000 },
    { -0.641457,  0.462097, -0.612372,  0.000000 },
    { -0.183013,  0.683013,  0.707107,  0.000000 },
    {  0.000000,  0.000000,  0.000000,  1.000000 }
}

MM_R_a =
array[4][1] {
    {  4.434831 },
    {  1.214589 },
    {  2.803043 },
    {  0.000000 }
}

MM_Rot_313_b =
array[4][4] {
    {  0.745010,  0.565650, -0.353553,  0.000000 },
    { -0.641457,  0.462097, -0.612372,  0.000000 },
    { -0.183013,  0.683013,  0.707107,  0.000000 },
    {  0.000000,  0.000000,  0.000000,  1.000000 }
}

MM_R_b =
array[4][1] {
    {  4.434831 },
    {  1.214589 },
    {  2.803043 },
    {  0.000000 }
}


Post a reply to this message

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