POV-Ray : Newsgroups : povray.text.scene-files : Lissajou-Knot generator Server Time
1 Jul 2024 02:58:10 EDT (-0400)
  Lissajou-Knot generator (Message 1 to 1 of 1)  
From: Lutz-Peter Hooge
Subject: Lissajou-Knot generator
Date: 8 Dec 2001 21:33:03
Message: <MPG.167cebaf2633b3e89896cc@news.povray.org>
This is mostly a conversion of the program found over here:
http://freespace.virgin.net/r.jennings/lissa.htm
to a pure POV-Script.

#version 3.5; // 3.1 should work, except for the sky-sphere (uses 
no_image)

camera
{    
	location <0,0,-32>
	look_at <0,0,0>
}               

light_source
{
	<1,1,-1>*20   
	color rgb .7*<.9,1,.9>
}  

light_source
{
	<.5,-2,-1>*20   
	color rgb <.7,.7,1>*.5
}  

// sky-sphere
sphere
{                          
	0,1
	pigment{wrinkles scale .5}
	finish{diffuse 0 ambient 1}
	inverse
	no_image
	scale 100000
	
}

/*******************************************************************
*                                                                  *
*  Adjust these parameters to generate the desired Lissajou-Shape  *
*                                                                  *
*******************************************************************/

#declare Method=3;
/*
To choose which set of generating functions to use.  
*/   

#declare R=10; 
/*
An positive integer that controls the over all size of the
generated figure.  If R is set to 10, no coordinate will be
greater than +/-10.
*/ 

#declare A=10; 
/*
One of the variables that affects generation:  It changes
the period of the equations, changing the figure.  It must
be a positive INTEGER
*/  

#declare B=25;

/*
Like the A variable, but it is used in different places in
the equations.
*/

#declare exp_X=1;
#declare exp_Y=1;
#declare exp_Z=1;
/*
These are exponents in the generation functions.  They apply
to the x, y, and z coordinate equations respectively. 
Positive integers from 1 to 9.
*/ 

#declare Sphere_Radius=1;
/*
This controls the size of the spheres that make-up the
figure.  Float. 
*/ 

#declare Sphere_Number=1000;
/*
Use this to say how many spheres/dots you want in the
generated figure.  The more spheres you have, the smoother
it looks, but at the expense of a longer tracing time.
*/ 

#declare Smooth=true;
#declare Blob=false;
/*
Smooth: Specifies if the Shperes should be connected by cylinders -> 
smoother
Blob: Use a Blob Object instead singel shperes? Smooth is ignored if 
Blob=True
Blob needs a considerably higher Sphere_Number to look smooth, but allows 

for faster transparent objects than using merge
*/

#declare Clock=1;
//#declare Clock=clock;
/*
Set this to something dependent of clock to animate it. Else use 1
*/


/*************************
*                        *
*  End of paramter part  *
*                        *
*************************/

// Texture:
#declare liss_mat=
material		
{
	texture
	{
		pigment
		{
			color rgb 1 
			#if(Blob) transmit .9 #end
		}
		
		finish
		{
			specular 1
			reflection .5
			conserve_energy
		}
	} 
	#if(Blob)interior {ior 1.5 fade_color <.3,.8,.8> fade_power 2001 
fade_distance .1}#end
}
		

// different Functions:
#macro Method1(T)
	<
		R*sin(A*T)*cos(B*T)^exp_X,
		R*sin(A*T)*sin(B*T)^exp_Y,
		R*cos(A*T)^exp_Z         
	>
#end

#macro Method2(T)
	<
		R*sin(A*T)*cos(B*T)^exp_X,
		R*cos(A*T)*cos(B*T)^exp_Y,
		R*sin(A*T)^exp_Z
	>
#end

#macro Method3(T)
	<
		R*sin(A*T)*sin(B*T)^exp_X,
		R*sin(A*T)*cos(B*T)^exp_Y,
		R*sin(A*T)^exp_Z
	>
#end

#macro Method4(T)
	<
		R/4* A*sin(2*(T-pi/12))^exp_X,
		R/4*-B*cos(T)^exp_Y,
		R*sin(A*T)^exp_Z
	>
#end

#macro Method5(T)
	<
		R*sin(A*T)*cos(A*T)^exp_X,
		R*sin(B*T)*sin(B*T)^exp_Y,
		R*sin(T)^exp_Z
	>
#end

#macro Val(Method,T) 
	#switch(Method)
		#case(1)
			#local return=Method1(T); 
		#break
		#case(2)
			#local return=Method2(T);
		#break
		#case(3)
			#local return=Method3(T);
		#break
		#case(4)
			#local return=Method4(T);
		#break
		#case(5)
			#local return=Method5(T);
		#break
	#end       
	return
#end 

    

// (try to) calculate correct range for T 
// maybe buggy
#macro ggT(a,b)
	#local A=a; #local B=b;
	#local remainder = 0;
	#while (B != 0)
      		#local remainder = mod(A,B);
      		#local A = B;
      		#local B = remainder;
	#end
	A
#end

#if(Method=4)
	#declare GGT=ggT(A,2);
#else
	#declare GGT=ggT(A,B);
#end

#declare t_max=pi*2/GGT; 

// object declaration
#declare lissajou=#if(Blob)blob
#else union #end
{
	#declare i=0;
	#declare i_max=t_max*Clock;
	#declare i_step=t_max/Sphere_Number;  
	#declare V_old=100*R*x; // just make sure it is initially far away 
from the rest of the Shape
	#while(i<=i_max)
	
		#declare V=Val(Method,i);
		sphere
		{
			V,Sphere_Radius #if(Blob),.5#end
		}                      
		
		// cylinder for smooting
		#if(vlength(V_old-V)<R/2 & Smooth & vlength(V_old-V)!=0 & 
!Blob)
			cylinder
			{
				V,V_old,Sphere_Radius
			}
		#end    
		#declare V_old=V;
		
		#declare i=i+i_step;
	#end
	
	#if(Blob)threshold .7#end
}	


object
{
	lissajou

	rotate x*65
	material
	{
		liss_mat
	}
	no_shadow
}


Post a reply to this message

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