POV-Ray : Newsgroups : povray.animations : Simulating [parametric] nested loop in animation scene file. Server Time
28 Mar 2024 16:28:00 EDT (-0400)
  Simulating [parametric] nested loop in animation scene file. (Message 1 to 2 of 2)  
From: Bald Eagle
Subject: Simulating [parametric] nested loop in animation scene file.
Date: 19 Oct 2016 13:00:01
Message: <web.5807a583603cf4ffb488d9aa0@news.povray.org>
Hi folks,

I wanted to animate the construction of some meshes based on parametric
equations, and am grappling with how to "linearize" the SDL so that I get the
behaviour of the Theta-Phi nested loop over the linear clock sequence.

I'm guessing the easiest way would be to have Phi follow a sawtooth type
function, which would imply using mod() - but I'm getting stuck.

Here's what I've worked out so far - I'd appreciate a little help visualizing
how to formulate the specific mod() function I need for this:

=========================================================

#declare ClockStep = 0.001;

#declare T_begin = -pi;
#declare T_end = pi;
#declare T_span = T_end-T_begin;

#declare P_begin = 0;
#declare P_end = 2*pi;
#declare P_span = P_end-P_begin;
#declare P_divisions = 36;


#for (Clock, 0, 1, ClockStep)

 #declare Theta = T_begin + (Clock*T_span);

  #declare Phi = P_begin + (P_span * mod (Clock, 1/P_divisions));

  #debug concat( " Clock = ", str(Clock, 3, 3),  " Theta = ", str(Theta, 3, 3),
" Phi = ", str(Phi, 3, 3), "\n")

#end // end for Clock


Post a reply to this message

From: Bald Eagle
Subject: Re: Simulating [parametric] nested loop in animation scene file.
Date: 20 Oct 2016 10:15:00
Message: <web.5808d0b37fd06a0b488d9aa0@news.povray.org>
I have something that works - partially - it doesn't seem to automatically give
a mesh as neat and complete as my static SDL scene does - this needed guessing
and tweaking the increments manually

I also seem to get an alternating brick arrangement rather than the radial array
of quadrilaterals that I do in the original.   I'm guessing I may have switched
up Theta and Phi somehow...   I'll have to look into that.


#version 3.7;

#include "colors.inc"
#include "debug.inc"

global_settings {
  assumed_gamma 1.0
}

camera {
   location  <0, 2, -30.0>
   look_at   <0.0, 0.0,  0.0>
 right    x*image_width/image_height
}

light_source {
  0*x                  // light's position (translated below)
  color rgb <1,1,1>    // light's color
  translate <-20, 40, -20>
}

#macro _CH2RGB (HH)
   #local H = mod(HH, 360);
   #local H = (H < 0 ? H+360 : H);
   #switch (H)
      #range (0, 120)
         #local R = (120-  H) / 60;
         #local G = (  H-  0) / 60;
         #local B = 0;
      #break
      #range (120, 240)
         #local R = 0;
         #local G = (240-  H) / 60;
         #local B = (  H-120) / 60;
      #break
      #range (240, 360)
         #local R = (  H-240) / 60;
         #local G = 0;
         #local B = (360-  H) / 60;
      #break
   #end
   <min(R,1), min(G,1), min(B,1)>
#end

#macro _CHSV2RGB(Color)
   #local HSVFT = color Color;
   #local H = (HSVFT.red);
   #local S = (HSVFT.green);
   #local V = (HSVFT.blue);
   #local SatRGB = _CH2RGB(H);
   #local RGB = ( ((1-S)*<1,1,1> + S*SatRGB) * V );
   <RGB.red,RGB.green,RGB.blue,(HSVFT.filter),(HSVFT.transmit)>
#end


#declare cot = function (QQ) {cos(QQ)/sin(QQ)}

#declare ClockStep = 0.001;

#declare T_begin = 0;
#declare T_end = 2*pi;
#declare T_span = T_end-T_begin;

#declare P_begin = -pi;
#declare P_end = pi;
#declare P_span = P_end-P_begin;
#declare P_divisions = 360;

#declare r0 = 10;
#declare r1 = 4;

#declare   Phi_inc = 2*pi*ClockStep*40; //(2*pi/360)*6;
#declare Theta_inc = 2*pi*ClockStep*25; //(2*pi/360)*2;
#declare Radius = 0.02;
#declare Spheres = true;
#declare Faces = true;
#declare Mesh = true;
#declare Colored = false;
#declare Spec = 0.0;
#declare Saturation = 0.8;

#declare X = function (T, P, R, r) {cos(T) * ( R + r * cos(P) )}
#declare Y = function (T, P, R, r) {sin(T) * ( R + r * cos(P) )}
#declare Z = function (P, r) {r * sin(P)}

#for (Clock, 0, 1, ClockStep)

 #declare Theta = T_begin + (Clock*T_span);

  //#declare Phi = P_begin + (P_span * mod (Clock, 1/P_divisions));
  //#declare Phi = -(2*1/pi)*atan2(cot(Clock*pi/P_divisions),1);
  #declare Phi = P_begin + P_span * (Clock*P_divisions -
floor(Clock*P_divisions));

  //#debug concat( " Clock = ", str(Clock, 3, 3),  " Theta = ", str(Theta, 3,
3), " Phi = ", str(Phi, 3, 3), "\n")

 #declare X1 = X (Theta, Phi, r0, r1); //cos(Theta) * ( r0 + r1 * cos(Phi) );
 #declare X2 = X (Theta, Phi + Phi_inc, r0, r1); //cos(Theta) * ( r0 + r1 *
cos(Phi + Phi_inc) );
 #declare X3 = X (Theta + Theta_inc, Phi + Phi_inc, r0, r1); //cos(Theta +
Theta_inc) * ( r0 + r1 * cos(Phi + Phi_inc) );
 #declare X4 = X (Theta + Theta_inc, Phi, r0, r1); //cos(Theta + Theta_inc) * (
r0 + r1 * cos(Phi) );

 #declare Y1 = Y (Theta, Phi, r0, r1); //sin(Theta) * ( r0 + r1 * cos(Phi) );
 #declare Y2 = Y (Theta, Phi + Phi_inc, r0, r1); //sin(Theta) * ( r0 + r1 *
cos(Phi + Phi_inc) );
 #declare Y3 = Y (Theta + Theta_inc, Phi + Phi_inc, r0, r1); //sin(Theta +
Theta_inc) * ( r0 + r1 * cos(Phi + Phi_inc) );
 #declare Y4 = Y (Theta + Theta_inc, Phi, r0, r1); //sin(Theta + Theta_inc) * (
r0 + r1 * cos(Phi) );

 #declare Z1 = Z (Phi, r1);
 #declare Z2 = Z (Phi + Phi_inc, r1);
 #declare Z3 = Z (Phi + Phi_inc, r1);
 #declare Z4 = Z (Phi, r1);

 #declare P1 = <X1, Y1, Z1>;
 #declare P2 = <X2, Y2, Z2>;
 #declare P3 = <X3, Y3, Z3>;
 #declare P4 = <X4, Y4, Z4>;


 #declare Color = _CHSV2RGB(<Theta*60, Saturation, 1, 0, 0>);

 #if (Faces)
  triangle {<X1, Y1, Z1>, <X2, Y2, Z2>, <X3, Y3, Z3> texture {pigment {color
Color} finish {phong 0.3}} no_shadow}
  triangle {<X3, Y3, Z3>, <X4, Y4, Z4>, <X1, Y1, Z1> texture {pigment {color
Color} finish {phong 0.3}} no_shadow}
 #end // end if Faces

 #if (Spheres)
  sphere {P1, Radius*2 texture {pigment {color Color} finish {phong 0.3}}
no_shadow}  // red spheres
  sphere {P2, Radius*2 texture {pigment {color Color} finish {phong 0.3}}
no_shadow}  // red spheres
  sphere {P3, Radius*2 texture {pigment {color Color} finish {phong 0.3}}
no_shadow}  // red spheres
  sphere {P4, Radius*2 texture {pigment {color Color} finish {phong 0.3}}
no_shadow}  // red spheres
 #end // end if Spheres

 #if (Mesh)
   cylinder {P1, P2, Radius
    #if (Colored)
     texture {pigment {color Color} finish {phong 0.3}} no_shadow}
    #else
     texture {pigment {Black} finish {specular Spec}} no_shadow}
    #end

   cylinder {P2, P3, Radius
    #if (Colored)
     texture {pigment {color Color} finish {phong 0.3}} no_shadow}
    #else
     texture {pigment {Black} finish {specular Spec}} no_shadow}
    #end

   cylinder {P3, P4, Radius
    #if (Colored)
     texture {pigment {color Color} finish {phong 0.3}} no_shadow}
    #else
     texture {pigment {Black} finish {specular Spec}} no_shadow}
    #end

   cylinder {P4, P1, Radius
    #if (Colored)
     texture {pigment {color Color} finish {phong 0.3}} no_shadow}
    #else
     texture {pigment {Black} finish {specular Spec}} no_shadow}
    #end
  #end // end if Mesh

#end // end for Clock


Post a reply to this message

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