POV-Ray : Newsgroups : povray.advanced-users : Rotation between 2 angles Server Time
23 Dec 2024 02:24:37 EST (-0500)
  Rotation between 2 angles (Message 1 to 3 of 3)  
From: Fractracer
Subject: Rotation between 2 angles
Date: 6 Jan 2014 08:50:01
Message: <web.52cab4641b5a436f673d78420@news.povray.org>
I write a macro use for create path for animations, the macro return an array of
<x,y,z> values. The problem I have is: how do I make to have a good rotation
between two angles? Actually the object look alwways in the same direction.
Here is the macro:

#macro calc_path(nbr_elem, AngleXY, AngleZ, seed1)
 #local S0 = 0;    //start
 #local S1 = nbr_elem;  //end
 #local ALEA = seed(seed1);

 #local Values = array[S1]
 #local OX = 0;  //Old X;
 #local OY = 0;  //Old Y;
 #local OZ = 0;  //Old Z;
 #local OA = 0;  //Old Angle;
 #local OAz = 0;  //Old Angle z;

 #local X = 0;
 #local Y = 0;
 #local Z = 0;
 #local AC = AngleXY;
 #local AD = AC/2;

 #while (S0<S1)
  #local NA = (AD - floor(rand(ALEA)*AC))+OA;
  #local OA = mod(NA,360);
  #local C = cosd(NA);
  #local S = sind(NA);

  #local X = OX+C;
  #local Y = OY+S;

  #local NAz = floor(rand(ALEA)*AngleZ)+OAz;
  #local OAz = mod(NAz,360);
  #local Sz = sind(NAz);
  #local Z = OZ+Sz;
  #local Values[S0]= <X,Y,Z>;
  #local OX = X;
  #local OY = Y;
  #local OZ = Z;
  #local S0 = S0+1;
 #end
 Values
#end

And the initialisation and use of the macro.

#local ELM = 25;
#local V = array[ELM];

#local V = calc_path(ELM, 100, 70, 1234);

#local Shape = union {
 box {<-0.25,0.0,-0.1>  <0.5,0.25,0.1> pigment {color rgb <0.1,0.1,0.1>}}
 box {< 0.25,0.1,-0.3>  <0.5,0.15,0.3> pigment {color rgb <0.5,0.5,0.5>}}
}

union {
 #local start = 0;
 #while (start<ELM)
     object {
     Shape
 translate V[start]
 }
 #local start = start+1;
 #end
}

Can somebody help me?


Post a reply to this message

From: Alain
Subject: Re: Rotation between 2 angles
Date: 6 Jan 2014 19:29:39
Message: <52cb4a73@news.povray.org>

> I write a macro use for create path for animations, the macro return an array of
> <x,y,z> values. The problem I have is: how do I make to have a good rotation
> between two angles? Actually the object look alwways in the same direction.
> Here is the macro:
>
> #macro calc_path(nbr_elem, AngleXY, AngleZ, seed1)
>   #local S0 = 0;    //start
>   #local S1 = nbr_elem;  //end
>   #local ALEA = seed(seed1);
>
>   #local Values = array[S1]
>   #local OX = 0;  //Old X;
>   #local OY = 0;  //Old Y;
>   #local OZ = 0;  //Old Z;
>   #local OA = 0;  //Old Angle;
>   #local OAz = 0;  //Old Angle z;
>
>   #local X = 0;
>   #local Y = 0;
>   #local Z = 0;
>   #local AC = AngleXY;
>   #local AD = AC/2;
>
>   #while (S0<S1)
>    #local NA = (AD - floor(rand(ALEA)*AC))+OA;
>    #local OA = mod(NA,360);
>    #local C = cosd(NA);
>    #local S = sind(NA);
>
>    #local X = OX+C;
>    #local Y = OY+S;
>
>    #local NAz = floor(rand(ALEA)*AngleZ)+OAz;
>    #local OAz = mod(NAz,360);
>    #local Sz = sind(NAz);
>    #local Z = OZ+Sz;
>    #local Values[S0]= <X,Y,Z>;
>    #local OX = X;
>    #local OY = Y;
>    #local OZ = Z;
>    #local S0 = S0+1;
>   #end
>   Values
> #end
>
> And the initialisation and use of the macro.
>
> #local ELM = 25;
> #local V = array[ELM];
>
> #local V = calc_path(ELM, 100, 70, 1234);
>
> #local Shape = union {
>   box {<-0.25,0.0,-0.1>  <0.5,0.25,0.1> pigment {color rgb <0.1,0.1,0.1>}}
>   box {< 0.25,0.1,-0.3>  <0.5,0.15,0.3> pigment {color rgb <0.5,0.5,0.5>}}
> }
>
> union {
>   #local start = 0;
>   #while (start<ELM)
>       object {
>       Shape
>   translate V[start]
>   }
>   #local start = start+1;
>   #end
> }
>
> Can somebody help me?
>
>

The problem with using an array is that you only have discreete values. 
If you want to change the number of frames in the animation, you need to 
recompute the whole array.

Make a spline from your array. Any spline but the linear one can do.
Next, take two points: one for the location and a second one a little 
bit away. Use them to orient your object. You can take a look at the 
splinefollow example scene as an example of the principle.
The advantage been that you now can interpolate between your defined 
points. This can mean that you may need to define fewer points.

Another option would be to have a spline for the location and another 
one for the orientation: The first spline gives the rotation or 
orientation of your object, the second one been used to translate the 
object to the desider location. This enable you to have complete 
controll of the orientation of your object. You can do something similar 
for the camera: One spline define the path of the camera, the second 
define the path of the look_at point.



Alain


Post a reply to this message

From: Fractracer
Subject: Re: Rotation between 2 angles
Date: 7 Jan 2014 04:50:00
Message: <web.52cbcceee1c7c993673d78420@news.povray.org>
Alain <kua### [at] videotronca> wrote:

> The problem with using an array is that you only have discreete values.
> If you want to change the number of frames in the animation, you need to
> recompute the whole array.
>
> Make a spline from your array. Any spline but the linear one can do.
> Next, take two points: one for the location and a second one a little
> bit away. Use them to orient your object. You can take a look at the
> splinefollow example scene as an example of the principle.
> The advantage been that you now can interpolate between your defined
> points. This can mean that you may need to define fewer points.
>
> Another option would be to have a spline for the location and another
> one for the orientation: The first spline gives the rotation or
> orientation of your object, the second one been used to translate the
> object to the desider location. This enable you to have complete
> controll of the orientation of your object. You can do something similar
> for the camera: One spline define the path of the camera, the second
> define the path of the look_at point.
>
>
>
> Alain

Thank you very much for your answer, it's exactly what I want.

Lionel.


Post a reply to this message

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