POV-Ray : Newsgroups : povray.general : Convert translate/rotate list to single translate/rotate-Statement Server Time
28 Dec 2024 23:19:11 EST (-0500)
  Convert translate/rotate list to single translate/rotate-Statement (Message 1 to 8 of 8)  
From: Juergen
Subject: Convert translate/rotate list to single translate/rotate-Statement
Date: 7 Dec 2013 12:25:00
Message: <web.52a359beeb205622a1cf996b0@news.povray.org>
Hello,

I've the following problem:
I'am using a big smooth_triangle mesh, which I translate and rotate on vertics
level by macros. The translate's and rotate's are needed for modification to the
mesh for a later animation.

After the modification I want to translate/rotate the mesh in it's original
postion. Currently I'm storing all applied translate/rotate in a list and do
them backwards. This works but needs lot of parsing time.

My question is now, how can I convert the list of translate's/rotate's to a
single translate/rotate statement ?


translate <1,2,3>
rotate <30,50,-20>
translate<-2,4,-5>
rotate<-40,130,70>
.....// lots of more transforms
rotate <10,0,40>

  |
  |
  V

translate <tx,ty,tz>
rotate <rx,ry,rz>

I need the values t?,r? so that I can use them in macros.



Post a reply to this message

From: Le Forgeron
Subject: Re: Convert translate/rotate list to single translate/rotate-Statement
Date: 7 Dec 2013 13:09:13
Message: <52a36449$1@news.povray.org>
Le 07/12/2013 18:24, Juergen nous fit lire :
> Hello,
> 
> I've the following problem:
> I'am using a big smooth_triangle mesh, which I translate and rotate on vertics
> level by macros. The translate's and rotate's are needed for modification to the
> mesh for a later animation.
> 
> After the modification I want to translate/rotate the mesh in it's original
> postion. Currently I'm storing all applied translate/rotate in a list and do
> them backwards. This works but needs lot of parsing time.
> 
> My question is now, how can I convert the list of translate's/rotate's to a
> single translate/rotate statement ?
> 
> 
> translate <1,2,3>
> rotate <30,50,-20>
> translate<-2,4,-5>
> rotate<-40,130,70>
> .....// lots of more transforms
> rotate <10,0,40>
> 
>   |
>   |
>   V
> 
> translate <tx,ty,tz>
> rotate <rx,ry,rz>
> 
> I need the values t?,r? so that I can use them in macros.

Do you need to know the t* & r*, or just to have them available as a
transform for your macro ?

Look around
http://wiki.povray.org/content/Documentation:Tutorial_Section_2.2#Matrix

If you really need t* & r*, then you need to learn how to transform each
operation as a weighted 4D matrix, multiply them in order and interpret
it (if possible) to extract r* & t*.

But I doubt it would be possible.
(The single transform with a single 4D matrix is no problem, but it
seldom turn to be only a translate+rotate )


Post a reply to this message

From: Juergen
Subject: Re: Convert translate/rotate list to single translate/rotate-Statement
Date: 7 Dec 2013 14:30:00
Message: <web.52a3763a146379bfa1cf996b0@news.povray.org>
Le_Forgeron <jgr### [at] freefr> wrote:
> Le 07/12/2013 18:24, Juergen nous fit lire :
>
> Do you need to know the t* & r*, or just to have them available as a
> transform for your macro ?
>
> Look around
> http://wiki.povray.org/content/Documentation:Tutorial_Section_2.2#Matrix
>
> If you really need t* & r*, then you need to learn how to transform each
> operation as a weighted 4D matrix, multiply them in order and interpret
> it (if possible) to extract r* & t*.
>
> But I doubt it would be possible.
> (The single transform with a single 4D matrix is no problem, but it
> seldom turn to be only a translate+rotate )

Currently I need the concret values for the translate ans rotate.

The actual situation is, that I've two macros

AnimTranslate(arVertics, vTrans)  and  AnimRotate(arVertics, vRot)

to modity the mesh. arVertics ist an array with the vertics ofthe mesh.
AnimTranslate() simply adds the offset to each vector, AnimRotate() internally
uses "vrotate" to make the rotation.


Post a reply to this message

From: Ger
Subject: Re: Convert translate/rotate list to single translate/rotate-Statement
Date: 7 Dec 2013 14:41:36
Message: <52a379f0$1@news.povray.org>
Juergen wrote:

> Hello,
> 
> I've the following problem:
> I'am using a big smooth_triangle mesh, which I translate and rotate on
> vertics level by macros. The translate's and rotate's are needed for
> modification to the mesh for a later animation.
> 
> After the modification I want to translate/rotate the mesh in it's
> original postion. Currently I'm storing all applied translate/rotate in a
> list and do them backwards. This works but needs lot of parsing time.
> 
> My question is now, how can I convert the list of translate's/rotate's to
> a single translate/rotate statement ?
> 
> 
> translate <1,2,3>
> rotate <30,50,-20>
> translate<-2,4,-5>
> rotate<-40,130,70>
> .....// lots of more transforms
> rotate <10,0,40>
> 
>   |
>   |
>   V
> 
> translate <tx,ty,tz>
> rotate <rx,ry,rz>
> 
> I need the values t?,r? so that I can use them in macros.
> 
> Jürgen

If I understand you correctly, you have a mesh that you act upon 
(rotate/translate/whatever) and then want to go back to the original mesh 
and act again with a different set of rotations/translations.

If so, then the easiest way is to store the mesh on hard disk during the 
first frame and at every following frame load it from disk and apply 
whatever you want to apply. That way you don't have to undo anything but 
start fresh with every frame.

-- 
Ger


Post a reply to this message

From: Juergen
Subject: Re: Convert translate/rotate list to single translate/rotate-Statement
Date: 7 Dec 2013 15:15:00
Message: <web.52a38191146379bfa1cf996b0@news.povray.org>
The problem is, that I modify parts of the mesh. First I translate/rotate the
mesh to align a part along an axis. The I can easyly modify a part of the mesh
(bending, scaling). Then I want to bring the mesh with the modified parts back
in base alignment.
Concret it is a human model exported from makehuman, which I want to animate
within povray completly with the build in macro landuage.



Post a reply to this message

From: clipka
Subject: Re: Convert translate/rotate list to single translate/rotate-Statement
Date: 7 Dec 2013 15:23:31
Message: <52a383c3@news.povray.org>
Am 07.12.2013 20:25, schrieb Juergen:
> Le_Forgeron <jgr### [at] freefr> wrote:
>> Le 07/12/2013 18:24, Juergen nous fit lire :
>>
>> Do you need to know the t* & r*, or just to have them available as a
>> transform for your macro ?
>>
>> Look around
>> http://wiki.povray.org/content/Documentation:Tutorial_Section_2.2#Matrix
>>
>> If you really need t* & r*, then you need to learn how to transform each
>> operation as a weighted 4D matrix, multiply them in order and interpret
>> it (if possible) to extract r* & t*.
>>
>> But I doubt it would be possible.
>> (The single transform with a single 4D matrix is no problem, but it
>> seldom turn to be only a translate+rotate )
>
> Currently I need the concret values for the translate ans rotate.
>
> The actual situation is, that I've two macros
>
> AnimTranslate(arVertics, vTrans)  and  AnimRotate(arVertics, vRot)
>
> to modity the mesh. arVertics ist an array with the vertics ofthe mesh.
> AnimTranslate() simply adds the offset to each vector, AnimRotate() internally
> uses "vrotate" to make the rotation.

Do you need to have AnimTranslate and AnimRotate as separate macros, or 
would it be ok if you had just one AnimTransform macro?

In the latter case, you'll want to use the following construct:


#declare MyTransform = transform {
   translate <1,2,3>
   rotate <30,50,-20>
   translate<-2,4,-5>
   rotate<-40,130,70>
   ......// lots of more transforms
   rotate <10,0,40>
}

#macro AnimTransform(arVertics, tTransform)
   ...
   #declare vNew = vtransform(vOld, tTransform);
   ...
#end


If you need to apply the inverse transform, you can also use:

#declare MyInvTransform = transform { MyTransform inverse }


You might think of a transform as a container of rotations, translations 
and scales to be applied in sequence; internally however, the sequence 
is compiled into a single equivalent matrix transform for better 
performance.


Post a reply to this message

From: Ger
Subject: Re: Convert translate/rotate list to single translate/rotate-Statement
Date: 7 Dec 2013 15:30:49
Message: <52a38579$1@news.povray.org>
Juergen wrote:

> The problem is, that I modify parts of the mesh. First I translate/rotate
> the mesh to align a part along an axis. The I can easyly modify a part of
> the mesh (bending, scaling). Then I want to bring the mesh with the
> modified parts back in base alignment.
> Concret it is a human model exported from makehuman, which I want to
> animate within povray completly with the build in macro landuage.
> 
> Jürgen

I see. That gives several headaches and a long lasting migraine.
Success :)


-- 
Ger


Post a reply to this message

From: Juergen
Subject: Re: Convert translate/rotate list to single translate/rotate-Statement
Date: 7 Dec 2013 16:35:00
Message: <web.52a39247146379bfa1cf996b0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> If you need to apply the inverse transform, you can also use:
>
> #declare MyInvTransform = transform { MyTransform inverse }

Hi,
this was the keyword :-)
Now it is working!

In the past I've experimented with vtransform, vinv_transform and some other
functions, but got no working code. The transform with the 'inverse' keyword was
working immediately.

Now I could reduce the parsing time from 57 to 33 seconds.

Thanks a lot to all!





------------
for intrests, here is the code doing the back-traansformation:

fAnimCnt,arAnimTrans and arAnimVek are initialisized by revious function calls.
fAnimCnt stores the number of transforms in the arrays.
arAnimTrans[] is the type of transformation, 1=translate, 2=rotate
arAnimVek[] stores the vector values of the transform
arVertics is an array with the vertics of the mesh (not in vetor format -
array[Num][3] to be compatible with my older macros)

    // build the transform-statement
    #local i=0;
    #local vtrans = transform {
      #while (i<fAnimCnt)
        #if (arAnimTrans[i]=1) // translate
          translate arAnimVek[i]
        #else
          rotate arAnimVek[i] // rotate
        #end
        #local i=i+1;
      #end
    }
    // the inverse transformation
    #local itrans=transform{vtrans inverse};

    // applying the transform to all vertics
    #local Size=dimension_size(arVertics,1);
    #local i=0;
    #while (i<Size)
      #local V=<arVertics[i][0],arVertics[i][1],arVertics[i][2]>;
      #local V=vtransform(V,itrans);
      #declare arVertics[i][0]=V.x;
      #declare arVertics[i][1]=V.y;
      #declare arVertics[i][2]=V.z;
      #local i=i+1;
    #end


Post a reply to this message

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