Some examples of spherical Lissajous curves created with POVRay.
##############################################################################
# This program created by Hans Mikelson February 1998
#
# This program generates a POV file so that 3D graphs can be
# rendered using the POV ray tracing package. The surface is mapped
# as a sphere for each data point sampled. This was configured for
# use on a Win95 computer. Some changes may need to be made for use on
# other systems. This program assumes that POVRay has been installed
# and that there is a path to it.
##############################################################################
# Define files for the template (header/footer), the data and the POV file.
$povfile="plotter.pov";
$scale =.25;
$radius = $scale;
# open the POV file.
open (POV, ">$povfile");
# Print the header
print POV "#version 3.0\n";
print POV "global_settings { assumed_gamma 2.2 }\n\n";
print POV "#include \"colors.inc\"\n";
print POV "#include \"shapes.inc\"\n";
print POV "#include \"textures.inc\"\n";
print POV "#include \"glass.inc\"\n";
print POV "#include \"stones.inc\"\n\n";
print POV "#include \"metals.inc\"\n\n";
print POV "camera {\n";
print POV "location <-2,-9,-2>\n";
print POV " look_at <-2,0,-2>}\n\n";
print POV "// Light sources \n";
print POV "light_source {<-30, 21, 40> color White}\n";
print POV "light_source {< 0, -8, -4> color White}\n";
print POV "light_source {< 2, 30, 3> color White}\n";
print POV "background { color rgb <1, 1, 1> }\n\n";
@ul = (.3,.3,.6);
@vl = (.2,.2,.9);
for ($j=0; $j<1; $j++)
{
for ($k=0; $k<1; $k++)
{
$u = $ul[$j];
$v = $vl[$k];
$rad = 2;
# Print the data.
for ($i=0; $i<800; $i++)
{
$t = $i * .1;
# Cosines
$cosu = cos($u*$t);
$cosv = cos($v*$t);
# Sines
$sinu = sin($u*$t);
$sinv = sin($v*$t);
# Compute X and Y
$xval = $rad*$sinu*$cosv;
$yval = $rad*$sinu*$sinv;
$zval = $rad*$cosu;
$colr=1/(1+$xval*$xval);
$colg=1/sqrt(1+abs($yval));
$colb=1/(1+$zval*$zval*$zval*$zval);
$xval += $j*5; $yval += $k*5;
print POV "sphere { <$xval, $zval, $yval>, $radius\n";
print POV " texture { pigment {color rgb <$colr, $colg, $colb>}}\n";
print POV " finish {caustics 1.0 phong 1 phong_size 300 reflection 0.15}\n";
print POV "}\n\n";
if ($i>0)
{
print POV "cylinder { <$xval, $zval, $yval>, <$xold, $zold, $yold> $radius\n";
print POV " texture { pigment {color rgb <$colr, $colg, $colb>}}\n";
print POV " finish {caustics 1.0 phong 1 phong_size 300 reflection 0.15}\n";
print POV "}\n\n";
}
$xold = $xval;
$yold = $yval;
$zold = $zval;
}
}}
close(POV);
# End of script
Hi, I was wondering if you could provide some more commentary on how your code works. What are the "magic numbers" in your ul and vl arrays, and what parameters did you use to describe the individual curves shown above? Thanks!
ReplyDeleteX = R sin u * cos v
DeleteY = R sin u * sin v
Z = R cos u
You could try some other parametric equations if you wanted to, maybe try something different for Z.
A Lissajous curve is usually observed on an oscilloscope with different frequency sine waves on the x and y inputs so it creates an interesting pattern especially if you have whole numbers. The spherical Lissajous I think I got from Clifford Pickover's Computer's and the Imagination. A set of parametric equations is used to generate the x, y, and z coordinates for the curve and a sphere is plotted at each coordinate. I also connect each sphere with a cylinder. $t is for time, $u and $v scale the frequency of the sinusoids. It looks like for this one I am just generating a single curve because $j and $k only generate one image. But I could make a 3x3 set of curves if I change the limits on the loops or go to length of the arrays. I must have liked (.3, .2) because that is the first one. Usually you would want to have different numbers for each pair of u and v generated. $r is for the radius of the circles and cylinders in case you want fatter or thinner graphs. The color scheme was chosen to vary in an "artistic" way.
Delete