POV-Ray : Newsgroups : povray.binaries.images : --- : Re: Harmonograph simulation Server Time
28 Apr 2024 21:04:38 EDT (-0400)
  Re: Harmonograph simulation  
From: Bald Eagle
Date: 27 Sep 2016 12:20:00
Message: <web.57ea9b8e3023a69ab488d9aa0@news.povray.org>
William F Pokorny <ano### [at] anonymousorg> wrote:

> Neat! I'd like to see the source code.
>
> Bill P.

I was interested too, and just grabbed some info from Wikipedia and worked out
something functional.
My head was not in "function-space" at the time, so I just embedded the formulas
in the loop.
I think initially I was going to try to make it an isosurface...

The HSV to RGB macros are copied into the SDL to keep the parse time down, as I
haven't had the roundtuits to install 3.71-etc

I was surprised and delighted to see how closely related these are to Lissajous
figures, which I was just recently fiddling with.  I guess if there's no
damping, then they are identical things.

I haven't implemented the moving paper portion of the code yet.

Now we just need an animated inverse kinematic harmonograph machine to go with
the output...   :D

I haven't gotten anything near as beautiful as Anthraquinone did - I guess it's
all in the skill of acquiring a good feel for the oscillation parameters, and
writing up a nice texture for the trace.

#######################################################################

#version 3.7;

global_settings {assumed_gamma 1.0}

#include "colors.inc"
#include "consts.inc"
#include "textures.inc"

#declare Size = 20;

camera {
 location <0, 0, -Size*2> // Front
 //location <0, Size*3, 10> // Top
 look_at  <0, 0, 10>
 right     x*image_width/image_height
 up y
}


light_source {<10, 10, -100> White shadowless}

#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 Line = 0.1;

#declare Amp = 4;
#declare Amp1 = 10;  // X
#declare Amp2 = 5;  // X
#declare Amp3 = 10;  // Y
#declare Amp4 = 5;  // Y

#declare Freq = 1;
#declare Freq1 = 10; // X
#declare Freq2 = 10; // X
//--------------------------------
#declare Freq3 = 10; // Y
#declare Freq4 = 160; // Y

#declare Phase = 0;
#declare Phase1 = pi/2; // X
#declare Phase2 = pi/3; // X
#declare Phase3 = 0; // Y
#declare Phase4 = pi/6; // Y

#declare Damp = 0.1;
#declare Damp1 = 0.1; // X
#declare Damp2 = 0.1; // X
#declare Damp3 = 0.1; // Y
#declare Damp4 = 0.1; // Y

// From:  https://en.wikipedia.org/wiki/Harmonograph
// movement of a damped pendulum:
// #declare X = function (T) { Amp*sin(T*Freq+Phase)*pow(e, (-Damp*T)) };


//the motion of a rod connected to the bottom of the pendulum along one axes
will be described by the equation

// #declare X = function (T) { Amp1*sin(T*Freq1+Phase1)*pow(e, (-Damp1*T)) +
Amp2*sin(T*Freq2+Phase2)*pow(e, (-Damp2*T)) };

// A typical harmonograph has two pendulums that move in such a fashion, and a
pen that is moved by two perpendicular rods connected to these pendulums.
// Therefore the path of the harmonograph figure is described by the parametric
equations

//#declare X = function (T) { Amp1*sin(T*Freq1+Phase1)*pow(e, (-Damp1*T)) +
Amp2*sin(T*Freq2+Phase2)*pow(e, (-Damp2*T)) };
//#declare Y = function (T) { Amp3*sin(T*Freq3+Phase3)*pow(e, (-Damp3*T)) +
Amp4*sin(T*Freq4+Phase4)*pow(e, (-Damp4*T)) };


#declare Iterations = 20;
#declare Step = 0.0001;

#for (i, 0, Iterations*2*pi, Step)
 #local T = i;
 #local X = Amp1*sin(T*Freq1+Phase1)*pow(e, (-Damp1*T)) +
Amp2*sin(T*Freq2+Phase2)*pow(e, (-Damp2*T));
 #local Y = Amp3*sin(T*Freq3+Phase3)*pow(e, (-Damp3*T)) +
Amp4*sin(T*Freq4+Phase4)*pow(e, (-Damp4*T));
 #local H = (360/Iterations)*i;
 #local Color = _CHSV2RGB(<H, 1, 1, 0, 0>);
   sphere {
    <X, Y, i>, Line
    texture {pigment {rgbft Color} finish {specular 0.6} }
    }
#end // end for i


Post a reply to this message

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