PDL::Graphics::TriDTriD_Tutorial
A practical user's guide for PDL::GRAPHICS::TriD. Showing code usage and expected visual output, so that new users can find the example code usages for thier 3D plotting project, and experimentation. It is meant as a supplement to "perldoc PDL::GRAPHICS::TriD", showing real code usages of the module's methods and settings.
This pod document, has been written so that it can be converted to html format, and PDF, both of which contain graphics, like screenshots, and highlighted source code , and links to sourcecode. If this text-only pod documentation seems wanting, please see the html or pdf version.
I am a Perl programmer, and almost all the examples will be in Perl script form; but you should be able to easily run the same commands in perldl or pdl2.
The PDL::GRAPHICS::TriD perl module, is an mouse interactive 3 dimensional visualization tool built on top of OpenGl. TriD uses PDL's piddles for storing data. It is NOT an exacting 3D graph, but a way to visualize space and relative shapes. Read "perldoc OpenGL" to see all the low level commands which the TriD module can theoretically use. The documentation on this topic is scattered, and even I don't understand the OpenGL concept fully.
I am somewhat familiar with eventloop systems, and the underlying OpenGL window, which TriD uses, is very similar to a Tk or Gtk2 eventloop. You have a window initialization, and an eventloop command which starts the thing going in loops, looking for events on each pass thru. I bring this up, because the actual TriD graphing tool hides much of this reality from the end user. Understanding that there actually is an OpenGL eventloop system running behind the scenes, is a big help when trying to understand TriD methods like keeptwiddling3d and nokeeptwiddling3d.
I include a pure OpenGL script as the first example below, so you can understand the eventloop system which TriD uses.
Finally, you need to be aware of what is called parametric equations. When you model a set of curves in higher dimensional spaces, it is often convenient to define x,y,and z in terms of parameters r and u. R and U give you 2 parameters for your xy plane position, and z gives a value and that xy position. See http://en.wikipedia.org/wiki/Parametric_equations for the complete explanation.
These are just a collection of scripts, which I have collected from various places on the net, or self-written, attempting to understand how the 3D display works. I, the author of this document, am not an expert on TriD, I'm just a librarian, and experimenter. I do not fully know myself how all the OpenGL functions work, I'm just presenting many simple examples, from which you can learn and experiment.
There are 2 things obvious, yet confusing, when first using the TriD viewport.
First: the axis are always relative to the maximum value that your piddles have in their respective dimensions. The actual 3d axis are usually refered to in a relative way from 0 to 1. This means that your actual place on the cartesian graph, sometimes actually is a ratio of the actual value divide by the maximum value in that dimension. This is a clever way of showing infinity in a finite viewport, or at least that is my perspective on it. You will find that you often need to specify positions as a ratio between 0 and 1 ... it's actually very zen. :-)
Second: You will notice that if you try to close the 3d viewport with your window manager's X button, you will get an dialog asking if you want to close the 3d window. When you use TriD, a simple hit of the 'Q' button closes the 3d window quietly. :-)
PDL::Graphics::TriDThis first example is just pure OpenGL to show you the eventloop which TriD uses under the hood.
A OpenGL rotating clipped cube:
#!/usr/bin/perl # # This is an example program from the legacy TriD/OpenGL/examples # directory moved here for reference. It only uses OpenGL features # so can probably be deprecated in favor of the Perl OpenGL # examples eventually. # # clip # # This program demonstrates arbitrary clipping planes. # Based on the "clip.c" program in the # OpenGL Programming Guide, Chapter 3, page 108, Listing 3-5. # However this program clips the front part of a rotating cube # with flat shaded faces instead of a wire frame sphere. # # the C synopsis of glClipPlane is # # void glClipPlane(GLenum plane,const GLdouble *equation ) # # For PERL the routine glpClipPlane was added, and the synopsis is: # # void glpClipPlane(GLenum plane,GLdouble a,GLdouble b,GLdouble c,GLdouble d) # # and the 4 double vector (equasion) is packaged by the XSUB. # Or you can still use glClipPlane but then you have to pack() the structure # # note: the statement f(@a) is equivalent to f($a[0],$a[1], ... $a[n]) # i.e. elements of a list are put on the call stack #
use OpenGL qw(:all);
sub tacky_cube {
local($s) = @_;
local(@x,@y,@z,@f);
local($i,$j,$k);
local(@r,@g,@b);
$s = $s/2.0;
@x=(-$s,-$s,-$s,-$s,$s,$s,$s,$s);
@y=(-$s,-$s,$s,$s,-$s,-$s,$s,$s);
@z=(-$s,$s,$s,-$s,-$s,$s,$s,-$s);
@f=(
0, 1, 2, 3,
3, 2, 6, 7,
7, 6, 5, 4,
4, 5, 1, 0,
5, 6, 2, 1,
7, 4, 0, 3,
);
@r=(1.0, 0, 0, 1.0, 1.0, 0);
@g=(0, 1.0, 0, 1.0, 0, 1.0);
@b=(0, 0, 1.0, 0, 1.0, 1.0);
for($i=0;$i<6;$i++){
glColor3f($r[$i],$g[$i],$b[$i]);
glBegin(GL_POLYGON);
for($j=0;$j<4;$j++){
$k=$f[$i*4+$j];
glVertex3d($x[$k],$y[$k],$z[$k]);
}
glEnd();
}
}
sub add_clip_plane {
# give the plane a slight tilt-away to prove we're not just
# clipping against the view volume
@eqn = (0.0, -0.3, -1.0, 1.2);
OpenGL::glpClipPlane(GL_CLIP_PLANE0, @eqn);
glEnable(GL_CLIP_PLANE0);
}
sub display{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef($spin, 0.0, 1.0, 0.0);
tacky_cube(3.0);
glPopMatrix();
glFlush();
glXSwapBuffers;
}
sub myReshape {
# glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 1.0 , 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity ();
}
OpenGL::glpOpenWindow(width => 400, height => 400,
attributes => [GLX_RGBA,GLX_DOUBLEBUFFER]);
glClearColor(0,0,0,1);
glShadeModel (GL_FLAT);
myReshape();
glDisable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glLoadIdentity (); glTranslatef (0.0, 0.0, -5.0); add_clip_plane;
# test glGetClipPlane() ($a,$b,$c,$d)=OpenGL::glpGetClipPlane(GL_CLIP_PLANE0); print "Clipping plane (a,b,c,d) = ($a,$b,$c,$d)\n";
$spin=0;
while(1) {$spin += 1.0; display;}

Now that you see how the OpenGL works, TriD builds on top of it. When you first run TriD, in default mode, it will open a small 300x300 window, which you can resize to full window, or any size in between which suits your purpose. You get a set of 3 dimensional axis, just like Cartesian space, and the whole image is rotatable with your mouse.
A simple torus example:
#!/usr/bin/perl use warnings; use strict; use PDL::LiteF; use PDL::Graphics::TriD;
my $torus = zeroes(3, 60, 20);
my $x = $torus->slice("(0)");
my $y = $torus->slice("(1)");
my $z = $torus->slice("(2)");
my $t = xlinvals $x, 0, 6.28;
my $u = ylinvals $x, 0, 6.28;
# ($x, $y, $z) = map {$torus->slice("($_)")} 0..2;
my $r = (1+sin(2*$t + $u))/2; my $g = (1+cos(2*$t + 2*$u))/2; my $b = (1+sin(2*$t + 3*$u))/2;
my $r_o = 3; my $r_i = 1;
$x .= ($r_o + $r_i * sin($u)) * sin($t) ; $y .= ($r_o + $r_i * sin($u)) * cos($t); $z .= $r_i * cos($u);
imag3d_ns $torus, [$r, $g, $b]; # color
The following are examples from the module's own perldoc and some which I wrote, to demonstrate TRiD's versatilty
This code uses the GD module to generate 6 numbered images, and assembles them into a dice like cube
#!/usr/bin/perl use warnings; use strict; use PDL::LiteF; use PDL::Graphics::TriD; # 3d display use GD; use GD::Text::Align; use PDL::NiceSlice; use PDL::IO::Pic;
GD::Image->trueColor(1);
my $image = new GD::Image(200,200); my $black = $image->colorAllocate(0,0,0); my $white = $image->colorAllocate(255,255,255); my $red = $image->colorAllocate(255,0,0); my $green = $image->colorAllocate(0,255,0); my $blue = $image->colorAllocate(0,0,255); my $yellow = $image->colorAllocate(255,255,0); my $grey = $image->colorAllocate(200,200,200);
my $gdt = GD::Text::Align->new($image,
font => 'Generic.ttf',
text => '',
color => $black,
valign => "center",
halign => "center",
) or die;
$gdt->set_font('Generic.ttf', 150) or die;
my %pdls;
my %color =(
1 => ['white',$white],
2 => ['red',$red],
3 => ['green',$green],
4 => ['blue',$blue],
5 => ['yellow',$yellow],
6 => ['grey',$grey],
);
foreach my $num (keys %color){
$image->filledRectangle( 0, 0, 200, 200, $color{$num}[1] );
$gdt->set_text($num);
$gdt->draw(100,100, 0) or die;
open(GD, "> z-$color{$num}[0].png" ) or die;#
binmode GD;
print GD $image->png;
close GD;
}
foreach my $num (keys %color){
$pdls{$num} = rim("z-$color{$num}[0].png" );
}
nokeeptwiddling3d();
hold3d();
# side 1 of space
imagrgb3d $pdls{1}->mv(2,0)->(:,-1:0,:)->float/256,
# {Points => [[1,0,0],[0,0,0],[0,0,1],[1,0,1]]}; #rotated +90 degress
{Points => [[1,0,1],[1,0,0],[0,0,0],[0,0,1]]};
#side 2 of space
imagrgb3d $pdls{2}->mv(2,0)->(:,-1:0,:)->float/256,
{Points => [[0,0,0],[1,0,0],[1,1,0],[0,1,0]]};
#side 3 of space
imagrgb3d $pdls{3}->mv(2,0)->(:,-1:0,:)->float/256,
{Points => [[1,0,0],[1,0,1],[1,1,1],[1,1,0]]};
#side 4 of space
imagrgb3d $pdls{4}->mv(2,0)->(:,-1:0,:)->float/256,
# {Points => [[0,0,1],[1,0,1],[1,1,1],[0,1,1]]}; #reversed
# {Points => [[0,1,1],[1,1,1],[1,0,1],[0,0,1]]}; #upside down
{Points => [[1,0,1],[0,0,1],[0,1,1],[1,1,1]]}; #good
#side 5 of space
imagrgb3d $pdls{5}->mv(2,0)->(:,-1:0,:)->float/256,
# {Points => [[0,0,0],[0,0,1],[0,1,1],[0,1,0]]};
{Points => [[0,0,1],[0,0,0],[0,1,0],[0,1,1]]};
#side 6 of space
imagrgb3d $pdls{6}->mv(2,0)->(:,-1:0,:)->float/256,
# {Points => [[0,1,0],[0,1,1],[1,1,1],[1,1,0]]};
{Points => [[0,1,1],[0,1,0],[1,1,0],[1,1,1]]};
#print "grabbing now\n"; #my $pic = grabpic3d(); # #imagrgb3d $pic; keeptwiddling3d(); twiddle3d();
#!/usr/bin/perl use warnings; use strict; use PDL; use PDL::Graphics::TriD;
# Draw out a trajectory in three-space my $t = sequence(100)/10; my $x = sin($t); my $y = cos($t); my $z = $t;
# Plot the trajectory as (x(t), y(t), z(t)) print "using line3d to plot a trajectory (press q when you're done twiddling)\n"; line3d [$x,$y,$z];
# If you give it a single piddle, it expects # the data to look like # ((x1, y1, z1), (x2, y2, z2), ...) # which is why we have to do the exchange: my $coords = cat($x, $y, $z)->xchg(0,1); print "again, with a different coordinate syntax (press q when you're done twiddling)\n"; line3d $coords;
# Draw a regularly-gridded surface:
my $surface = sqrt(rvals(zeroes(50,50))/2);
print "draw a mesh of a regularly-gridded surface using mesh3d\n";
mesh3d [$surface];
print "draw a regularly-gridded surface using imag3d\n";
imag3d [$surface], {Lines=>0};
# Draw a mobius strip: my $two_pi = 8 * atan2(1,1); $t = sequence(50) / 50 * $two_pi; # We want two paths: my $mobius1_x = cos($t) + 0.5 * sin($t/2); my $mobius2_x = cos($t); my $mobius3_x = cos($t) - 0.5 * sin($t/2); my $mobius1_y = sin($t) + 0.5 * sin($t/2); my $mobius2_y = sin($t); my $mobius3_y = sin($t) - 0.5 * sin($t/2); my $mobius1_z = $t - $two_pi/2; my $mobius2_z = zeroes($t); my $mobius3_z = $two_pi/2 - $t;
my $mobius_x = cat($mobius1_x, $mobius2_x, $mobius3_x); my $mobius_y = cat($mobius1_y, $mobius2_y, $mobius3_y); my $mobius_z = cat($mobius1_z, $mobius2_z, $mobius3_z);
my $mobius_surface = cat($mobius_x, $mobius_y, $mobius_z)->mv(2,0);
print "A mobius strip using line3d one way\n";
line3d $mobius_surface;
print "A mobius strip using line3d the other way\n";
line3d $mobius_surface->xchg(1,2);
print "A mobius strip using mesh3d\n";
mesh3d $mobius_surface;
print "The same mobius strip using imag3d\n";
imag3d $mobius_surface, {Lines => 0};
#!/usr/bin/perl use warnings; use strict; use PDL; use PDL::Graphics::TriD;
print " line3d (press q when you're done twiddling)\n"; line3d [sqrt(rvals(zeroes(50,50))/2)];
print "mesh3d (press q when you're done twiddling)\n"; mesh3d [sqrt(rvals(zeroes(50,50))/2)];
print " imag3d (press q when you're done twiddling)\n";
imag3d [sqrt(rvals(zeroes(50,50))/2)], {Lines=>0};
#!/usr/bin/perl use warnings; use strict; use PDL; use PDL::Graphics::TriD;
print " points3d (press q when you're done twiddling)\n"; points3d ndcoords(10,10,10)->clump(1,2,3);
print " spheres3d (press q when you're done twiddling)\n"; spheres3d ndcoords(10,10,10)->clump(1,2,3);
print " spheres3d (press q when you're done twiddling)\n"; spheres3d ndcoords(5,2,2)->clump(1,2,3);
#!/usr/bin/perl use warnings; use strict; use PDL; use PDL::Graphics::TriD;
my $x = sqrt(rvals(zeroes(50,50))/2);
imagrgb [0.5*sin(8*$x)+0.5,0.5*cos(8*$x)+0.5,0.5*cos(4*$x)+0.5];

#!/usr/bin/perl use warnings; use strict; use PDL; use PDL::Graphics::TriD;
my $colors = ndcoords(1,10,10)->clump(1,2,3);
print " (press q when you're done twiddling)\n";
imagrgb3d $colors, {Points => [[0,0,0],[1,0,0],[1,0,1],[0,0,1]]};
release3d();
my $colors1 = ndcoords(1,10,1)->clump(1,2,3);
print " (press q when you're done twiddling)\n";
imagrgb3d $colors1, {Points => [[0,0,0],[1,0,0],[1,0,1],[0,0,1]]};
release3d();
my $colors2 = ndcoords(10,10,1)->clump(1,2,3);
print " (press q when you're done twiddling)\n";
imagrgb3d $colors2, {Points => [[0,0,0],[1,0,0],[1,0,1],[0,0,1]]};
#!/usr/bin/perl use warnings; use strict; use PDL::LiteF;
# A simple contour plot in black and white use PDL::Graphics::TriD; use PDL::Graphics::TriD::Contours;
my $size = 25; my $x = (xvals zeroes $size,$size) / $size; my $y = (yvals zeroes $size,$size) / $size; my $z = (sin($x*6.3) * sin($y*6.3)) ** 3;
my $data=new PDL::Graphics::TriD::Contours($z,[$z->xvals/$size,$z->yvals/$size,0]);
PDL::Graphics::TriD::graph_object($data);
#!/usr/bin/perl use warnings; use strict; use PDL; use PDL::Graphics::TriD; use PDL::Graphics::TriD::Polygonize;
my $orig = PDL->pdl(0,0,0)->float;
sub func1 {
my($x,$y,$z) = map {$_[0]->slice("($_)")} 0..2;
my $r = $x**2 + 1.5*$y**2 + 0.3 * $z**2 + 5*($x**2-$y)**2;
my $res = ($r - 1) * -1;
# print $res;
return $res;
}
my $object = PDL::Graphics::TriD::StupidPolygonize::stupidpolygonize($orig,5, 50, 10,\&func1) ;
# output $object;
imag3d $object,{Lines => 0, Smooth => 1};
#!/usr/bin/perl use warnings; use strict; use PDL; use PDL::Graphics::TriD; use PDL::Graphics::TriD::Image;
# Number of subdivisions for lines / surfaces. my $size = 25;
# You remember this from the first 3d demo, right? my $r = (xvals zeroes $size+1,$size+1) / $size; my $g = (yvals zeroes $size+1,$size+1) / $size; my $b = ((sin($r*6.3) * sin($g*6.3)) ** 3)/2 + 0.5; # 3d cones
imagrgb [$r,$g,$b]; # Draw an 2D image
# How about this? imagrgb3d([$r,$g,$b]); # Draw an image on the lower plane
# Let's add the real image on top of this... hold3d();
imag3d([$r,$g,$b + 0.1], [$r,$g,$b]);
#!/usr/bin/perl use warnings; use strict; use PDL::LiteF; use PDL::Graphics::TriD;
print " (press q when you're done twiddling)\n";
# Draw out a line in 3-space my $t = sequence(100)/10;
my $x = $t; my $y = $t; my $z = $t; line3d [$x,$y,$z];
# add some curve and texture release3d(); $x = $t**.5; my $y = $t**3; my $z = $t**9; spheres3d [$x,$y,$z];
# go wild release3d(); $x = $t**.5; my $y = $t**3; my $z = sin $t; spheres3d [$x,$y,$z];
#!/usr/bin/perl use warnings; use strict; use PDL::LiteF; use PDL::Graphics::TriD;
my $i = zeroes(8000);
my $which = random($i) < 0.5; #print "$which\n";
my $x = grandom($i) * (1 + $which);
my $y = grandom($i) * (0.5 + $which);
my $z = grandom($i) * (2 - $which);
$x += $which * $y; $y += $which * $z; # Make it oblique
points3d [$x, $y, $z], [$which, 0.5*(1-$which), 1-$which];
#!/usr/bin/perl use warnings; use strict; use PDL::LiteF; use PDL::Graphics::TriD; use pdldump;
my $n = 3; my $d = 100;
while(1){
$n +=1;
$a= zeroes($n,$d); #and number of planes and sets density
#$a= zeroes(3,$d,$d); #adding extra dimensions only increases
#the number of points
my $r = random($a); #sets axis individually
print 'r ',join ' ',dims $r, "\n";
my $pdlc = zeroes(3); #each elem has 3 elements
my $col = $pdlc->slice('1:1,:,:'); #green
#my $col = $pdlc->slice('0:0,:,:'); #red
$col += 1;
print $r->xvals, "\n", $r->yvals, "\n";
print "press 'q' to continue cycling, hit your Exit Window control to quit";
points3d ['SURF2D',$r],$pdlc; # random points on planes where x = 0,1,2
}
#!/usr/bin/perl use warnings; use strict; use PDL::LiteF; use PDL::Graphics::TriD; use PDL::Graphics::TriD::ViewPort; #$PDL::Graphics::TriD::verbose = 1;
my $options ={
'height' => 500,
'width' => 500,
};
# get a 3d window with options my $win = PDL::Graphics::TriD::get_current_window( $options ); print "$win\n";
my $vp = $win->current_viewport;
my $g = $win->current_viewport()->graph();
if(!defined $g) {
$g = new PDL::Graphics::TriD::Graph();
$g->default_axes();
$win->current_viewport()->graph($g);
}
#print $g;
print "\nnormal\n"; twiddle3d();
print "\n3,3,3\n"; $vp->setview([3,3,3]); twiddle3d();
print "\n3,-3,3\n"; $vp->setview([3,-3,3]); twiddle3d();
#top
print "\n1,0,0,0\n";
my $transformer = $vp->transformer();
$transformer->set({WRotation=>[1,0,0,0]});
twiddle3d();
print "\n0,1,0,0\n";
$transformer = $vp->transformer();
$transformer->set({WRotation=>[0,1,0,0]});
twiddle3d();
print "\n0,0,1,0\n";
$transformer = $vp->transformer();
$transformer->set({WRotation=>[0,0,1,0]});
twiddle3d();
print "\n0,0,0,1\n";
$transformer = $vp->transformer();
$transformer->set({WRotation=>[0,0,0,1]});
twiddle3d();
print "\n0.5,-0.5,-0.5,-0.5\n";
print "East\n";
$transformer = $vp->transformer();
$transformer->set({WRotation=>[0.5,-0.5,-0.5,-0.5]});
twiddle3d();
print "\n0.6,-0.6,0,0\n";
print "South\n";
$transformer = $vp->transformer();
$transformer->set({WRotation=>[0.6,-0.6,0,0]});
twiddle3d();
These scripts were handed to me from Mark Baker, <mrbaker_mark@yahoo.com>
They are a beautiful set of piddles which walk you thru the concept of point animation, and the mathematical functions leading to visualizations of things like galaxy formation and the wave-particle duality.
It is the piddles which are of value. You can download the entire collection of over 20 scripts, spherical-dynamics.tgz, from the html link below.
Entire Script Collection as a downloadI will only show the highlights, in this tutorial. I have left them, in their unmodified, original state, in the download.
#!/usr/bin/perl use PDL::Ops; use PDL::Graphics::OpenGLQ; use PDL::Math; use PDL::AutoLoader; use PDL; use PDL::Graphics::TriD; use PDL::Graphics::TriD::Image; use PDL::Complex;
while(1){
nokeeptwiddling3d();
foreach $c (0) { $x= $c; $x1= $c;
$x=~ s/0/rvals/g; $x=~ s/1/xvals/; $x=~ s/2/yvals/; $x=~ s/3/zvals/;
$x1=~ s/0/sin/g; $x1=~ s/1/cos/; $x1=~ s/2/tan/; $x1=~ s/3/bessj1/;
foreach $d (0) { $y= $d;
$y=~ s/0/rvals/g; $y=~ s/1/xvals/; $y=~ s/2/yvals/; $y=~ s/3/zvals/;
foreach $e (1) { $z= $e;
$z=~ s/0/rvals/g; $z=~ s/1/xvals/; $z=~ s/2/yvals/; $z=~ s/3/zvals/;
for $f (1..36000) {
$bx = cos(zeros(10000)->($x)*bessj1($f*2*3.14));
$by = sin(ones(10000)->($y)+bessj0($f*2*3.14));
$bz = cos(zeros(10000)->($z)*bessj1($f*2*3.14));
$cx = sin(zeros(10000)->$x*$f*2*3.14);
$cy = rvals cos(zeros(10000)->$y*$f*2*3.14);
$cz = sin(zeros(10000)->$z*$f*2*3.14);
#$cz++;
$r = sin($cx)->rvals;
$g = cos($cy->rvals);
$b = bessj1($cz);
#points3d [cos($cx+$bx),cos($cy*$cx*$cz*$by*$bx*$bz),sin($cz+$bz)],[$r,$g,$b];
#points3d [($bx<=>$cx),($by<=>$cy),($bz<=>$cz)],[$r,$g,$b];
points3d [sin($cx*$bx),bessj1($cy*$cx*$cz*$by*$bx*$bz),sin($cz*$bz)],[$r,$g,$b];
#hold3d();
print $f," ",;
}
print $x," ",$y," ",$z," ",;
}}}}
#!/usr/bin/perl use PDL; use PDL::Graphics::TriD; use PDL::Graphics::TriD::Image; #use Math::Complex; require "bigfloat.pl"; # Number of subdivisions for lines / surfaces.
while(1){
for $z (1) {
for $y (30000000..40000000){
for $x (1){
keeptwiddling3d();
$f = xvals(sin(zeros(5535)));
$d = yvals(cos(zeros(5535)));
#$e = (sin(zeros(100)));
$e = xvals(sin($f*$d*$f));
$g = yvals(cos($d*$f*$d));
#$h = rvals($f*$d*$f);
$h = xvals(sin($e*$g*$e));
$i = yvals(cos($g*$e*$g));
$j = xvals(sin($h*$i*$h));
$k = yvals(cos($i*$h*$i));
$l = xvals(sin($j*$k*$j));
$m = yvals(cos($k*$j*$k));
$n = xvals(sin($l*$m*$l));
$o = yvals(cos($m*$l*$m));
$p = xvals(sin($n*$o*$n));
$q = yvals(cos($o*$n*$o));
$c = rvals($p*$q*$p);
$cx = (($z) * sin(2*3.1416*(($y)*$x))*$c);
$cy = (($z) * cos(2*3.1416*(($y)*$x))*$c);
#$cz = sin($c);
#$cz = (sin(($cx*$cy)*($cx+$cy)))**-1;
$cz = ($z**4)*sin(4*3.1416*(($y)*$x))*$c;
$r = (sin(($cz)));
$g = ((cos(($cy))));
$b = (sin(($cx)));
print "press and hold 'q' for animation\n";
points3d [($r*sin($cz-$cx-$cy)*($y*$x)),($g*sin($cz-$cx-$cy)*($y*$x)),($b*sin($cz-$cx-$cy)*($y*$x))], [$r,$g,$b];
#points3d [$r*sin($cz+$cx-$cy)*$y/$x,($g*sin($cz-$cx+$cy)*$y/($x)),$b*sin($cz)*($y/($x))], [$r,$g,$b];
#points3d [sin($cz+$cx-$cy)*$y/$x,sin($cz-$cx+$cy)*$y/($x),sin($cz)*($y/($x))], [$r,$g,$b];
#points3d [sin($cz+$cx-$cy)*$y/$x,sin($cz-$cx+$cy)*$y/($x),sin($cz)*($y/($x))], [$r,$g,$b];
#points3d [cos($cz+$cx-$cy)*$y/$x,cos($cz-$cx+$cy)*$y/($x),cos($cz)*($y/($x))], [$r,$g,$b];
#points3d [cos($cz+$cx-$cy)*1/2,sin($cz-$cx+$cy)*1/$cz,($cz)*(1/($cy))], [$r,$g,$b];
#points3d [cos($cz+$cx-$cy)*1/2,sin($cz-$cx+$cy)*1/$cx,($cz)*(1/($cy))], [$r,$g,$b];
#points3d [cos($cz+$cx-$cy)*1/2,sin($cz-$cx+$cy)*1/2,($cz)*1/($cy)], [$r,$g,$b];
#points3d [cos($cz+$cx-$cy),sin($cz-$cx+$cy),$z*($cz+$cx*$cy)], [$r,$g,$b];
#points3d [cos($cz+$cx+$cy),sin($cz-$cx+$cy),$z*($cz*$cx*$cy)], [$r,$g,$b];
#points3d [cos($cz+$cx+$cy),sin($cz+$cx+$cy),$z*($cz*$cx*$cy)], [$r,$g,$b];
#points3d [cos($cz-$cx-$cy),sin($cz+$cx+$cy),$z*($cz*$cx*$cy)], [$r,$g,$b];
#points3d [($cx),($cz-$cx-$cy),$cz], [$r,$g,$b];
#print $x," "," ",$y," ",$z;
}}}
}
#!/usr/bin/perl use PDL; use PDL::Graphics::TriD; use PDL::Graphics::TriD::Image; #use Math::Complex; require "bigfloat.pl"; # Number of subdivisions for lines / surfaces.
while(1){
for $z (1) {
for $y (30000000..40000000){
for $x (-1){
keeptwiddling3d();
$f = rvals(sin(zeros(5535)));##5535
$d = rvals(cos(ones(5535)));
#$e = (sin(zeros(100)));
$e = rvals(sin($f*$d*$f));
$g = rvals(cos($d*$f*$d));
#$h = rvals($f*$d*$f);
$h = rvals(sin($e*$g*$e));
$i = rvals(cos($g*$e*$g));
$j = rvals(sin($h*$i*$h));
$k = rvals(cos($i*$h*$i));
$l = rvals(sin($j*$k*$j));
$m = rvals(cos($k*$j*$k));
$n = rvals(sin($l*$m*$l));
$o = rvals(cos($m*$l*$m));
$p = rvals(sin($n*$o*$n));
$q = rvals(cos($o*$n*$o));
$c = rvals(sin($p*$q*$p));
$cx = (($z) * sin(2*3.1416*(($y)*$x))*$c);
$cy = (($z) * cos(2*3.1416*(($y)*$x))*$c);
#$cz = sin($c);
#$cz = (sin(($cx*$cy)*($cx+$cy)))**-1;
$cz = ($z**4)*sin(4*3.1416*(($y)*$x))*$c;
$r = (sin(($f)));#cz
$g = ((cos(($d))));#cy
$b = (sin(($f)));
print "press and hold 'q' for animation\n";
points3d [($r*sin($cz-$cx-$cy)*($y*$x)),($g*sin($cz-$cx-$cy)*($y*$x)),($b*sin($cz-$cx-$cy)*($y*$x))], [$r,$g,$b];
#points3d [$r*sin($cz+$cx-$cy)*$y/$x,($g*sin($cz-$cx+$cy)*$y/($x)),$b*sin($cz)*($y/($x))], [$r,$g,$b];
#points3d [sin($cz+$cx-$cy)*$y/$x,sin($cz-$cx+$cy)*$y/($x),sin($cz)*($y/($x))], [$r,$g,$b];
#points3d [sin($cz+$cx-$cy)*$y/$x,sin($cz-$cx+$cy)*$y/($x),sin($cz)*($y/($x))], [$r,$g,$b];
#points3d [cos($cz+$cx-$cy)*$y/$x,cos($cz-$cx+$cy)*$y/($x),cos($cz)*($y/($x))], [$r,$g,$b];
#points3d [cos($cz+$cx-$cy)*1/2,sin($cz-$cx+$cy)*1/$cz,($cz)*(1/($cy))], [$r,$g,$b];
#points3d [cos($cz+$cx-$cy)*1/2,sin($cz-$cx+$cy)*1/$cx,($cz)*(1/($cy))], [$r,$g,$b];
#points3d [cos($cz+$cx-$cy)*1/2,sin($cz-$cx+$cy)*1/2,($cz)*1/($cy)], [$r,$g,$b];
#points3d [cos($cz+$cx-$cy),sin($cz-$cx+$cy),$z*($cz+$cx*$cy)], [$r,$g,$b];
#points3d [cos($cz+$cx+$cy),sin($cz-$cx+$cy),$z*($cz*$cx*$cy)], [$r,$g,$b];
#points3d [cos($cz+$cx+$cy),sin($cz+$cx+$cy),$z*($cz*$cx*$cy)], [$r,$g,$b];
#points3d [cos($cz-$cx-$cy),sin($cz+$cx+$cy),$z*($cz*$cx*$cy)], [$r,$g,$b];
#points3d [($cx),($cz-$cx-$cy),$cz], [$r,$g,$b];
print $x," "," ",$y," ",$z;
}}}
}
#!/usr/bin/perl use PDL; use PDL::Graphics::TriD; use PDL::Graphics::TriD::Image; #use Math::Complex; require "bigfloat.pl"; # Number of subdivisions for lines / surfaces.
while(1){
for $z (1) {
for $y (2400000..2500000){
for $x (-1){
$f = rvals(sin(zeros(5535)));##5535
$d = rvals(cos(ones(5535)));
#$e = (sin(zeros(100)));
$e = rvals(sin($f*$d*$f));
$g = rvals(cos($d*$f*$d));
#$h = rvals($f*$d*$f);
$h = rvals(sin($e*$g*$e));
$i = rvals(cos($g*$e*$g));
$j = rvals(sin($h*$i*$h));
$k = rvals(cos($i*$h*$i));
$l = rvals(sin($j*$k*$j));
$m = rvals(cos($k*$j*$k));
$n = rvals(sin($l*$m*$l));
$o = rvals(cos($m*$l*$m));
$p = rvals(sin($n*$o*$n));
$q = rvals(cos($o*$n*$o));
$c = rvals(sin($p*$q*$p));
$cx = (($z) * sin(2*3.1416*(($y)*$x))*$c);
$cy = (($z) * cos(2*3.1416*(($y)*$x))*$c);
#$cz = sin($c);
#$cz = (sin(($cx*$cy)*($cx+$cy)))**-1;
$cz = ($z**4)*sin(4*3.1416*(($y)*$x))*$c;
$r = $cz*sin(($c));#cz
$g = $cy*(cos($c));#cy
$b = $cx*sin(($c));
#nokeeptwiddling3d(); #this will make automation run without q button press
print " press and hold 'q' for animation\n";
points3d [($r*sin($cz-$cx-$cy)*($y*$x)),($g*sin($cz-$cx-$cy)*($y*$x)),($b*sin($cz-$cx-$cy)*($y*$x))], [$r,$g,$b];
#points3d [$r*sin($cz+$cx-$cy)*$y/$x,($g*sin($cz-$cx+$cy)*$y/($x)),$b*sin($cz)*($y/($x))], [$r,$g,$b];
#points3d [sin($cz+$cx-$cy)*$y/$x,sin($cz-$cx+$cy)*$y/($x),sin($cz)*($y/($x))], [$r,$g,$b];
#points3d [sin($cz+$cx-$cy)*$y/$x,sin($cz-$cx+$cy)*$y/($x),sin($cz)*($y/($x))], [$r,$g,$b];
#points3d [cos($cz+$cx-$cy)*$y/$x,cos($cz-$cx+$cy)*$y/($x),cos($cz)*($y/($x))], [$r,$g,$b];
#points3d [cos($cz+$cx-$cy)*1/2,sin($cz-$cx+$cy)*1/$cz,($cz)*(1/($cy))], [$r,$g,$b];
#points3d [cos($cz+$cx-$cy)*1/2,sin($cz-$cx+$cy)*1/$cx,($cz)*(1/($cy))], [$r,$g,$b];
#points3d [cos($cz+$cx-$cy)*1/2,sin($cz-$cx+$cy)*1/2,($cz)*1/($cy)], [$r,$g,$b];
#points3d [cos($cz+$cx-$cy),sin($cz-$cx+$cy),$z*($cz+$cx*$cy)], [$r,$g,$b];
#points3d [cos($cz+$cx+$cy),sin($cz-$cx+$cy),$z*($cz*$cx*$cy)], [$r,$g,$b];
#points3d [cos($cz+$cx+$cy),sin($cz+$cx+$cy),$z*($cz*$cx*$cy)], [$r,$g,$b];
#points3d [cos($cz-$cx-$cy),sin($cz+$cx+$cy),$z*($cz*$cx*$cy)], [$r,$g,$b];
#points3d [($cx),($cz-$cx-$cy),$cz], [$r,$g,$b];
#print $x," "," ",$y," ",$z;
}}}
}
#!/usr/bin/perl use PDL; use PDL::Graphics::TriD; use PDL::Math;
# electron simulation by Mark Baker
nokeeptwiddling3d;
for $c(1..199999){
$n = 6.28*$c;
$x = $c*rvals((zeros(9000))*$c);
$cz = -1**$x*$c;
$cy = -1**$x*sin$x*$c;
$cx = -1**$c*rvals($x)*$c;
$w = $cz-$cy-$cx;
$g = sin($w);
$r = cos($cy+$c+$cz);
$b = cos($w);
$i = ($cz-$cx-$cy);
$q = $i*$n;
points3d [ $b*sin($q), $r*cos($q), $g*sin$q], [$g,$b,$r];
}
Mark Baker's text references, and equation explanations:
The book that I used to create the Piddle comes from Rodger Penrose's book "The Road to Reality"
From pages 562-564: We see the topic on 22.11 Spherical harmonics. We see that we can get the Cartesian coordinates for the equation
[eq.1]
x = sin [angle] cos [measure of longitude and latitude]
y= sin [angle] sin [measure of longitude and latitude]
z = cos [angle]
this is how I came up with the Spherical harmonic dynamic equation from the electron piddle ...
[eq.2]
$g = sin($w=$cz-$cy-$cx);
$r = cos($cy+$c+$cz);
$b = cos($w);
Now this is not the same equation as above , but it does help
us to see the [inner magnetic field] and the [outer electric field]
in a Spherical Harmonic Dynamical Geometry , which was my main concern...
Dissecting the equation further we have :
A equation I got from the book "Fundamental Formulas of Physics"
edited by Donald H. Menzel a Director at the Harvard Collage Observatory
page 7 Volume 1
[eq.3]
[a] sin [2*pi*frequency] [time] + [b] sin [2*pi*frequency] [time] = [c] sin([2*pi*frequency] [time] + [phase])
which is where the transformation below [eq.4] came from me trying to put the above [eq.3] equation in Cartesian coordinates that worked with the equation [eq.2] from [eq.1] ...
[eq.4]
$cz = -1**$x*$c;
$cy = -1**$x*sin$x*$c;
$cx = -1**$c*rvals($x)*$c;
------------------------------------
So looking at the full piddle we have :
for $c(1..99){ ## here c acts like the [2*pi* frequency] from [eq.3]
$n=6.28*$c; ## which is realized here
$x=$c*rvals((zeros(9000))*$c); ## some PDL minipulation
$cz = -1**$x*$c; ## a further transformation [eq.3] $cy = -1**$x*sin$x*$c; $cx = -1**$c*rvals($x)*$c;
$g = sin($w=$cz-$cy-$cx); ## a transformation of [eq.1] $r = cos($cy+$c+$cz); ## the main Geometry that ties together $b = cos($w); ## the transformation of [eq.4]
$i=($cz-$cx-$cy); ## additional Geometry needed
$q=$i*$n;
points3d[ $b*sin($q), $r*cos($q), $g*sin($q)], [$g,$b,$r] } ## further transformation that makes every thing work
-----------------------------------
So from the points3d perspective we see :
x = cos(-1**$x*$c - -1**$x*sin($x*$c) - -1**$c*rvals($x)*$c) *
sin( -1**$x*$c - -1**$x*sin($x*$c) - -1**$c*rvals($x)*$c * 2*O*$c)
y =cos(-1**$x*sin($x*$c) + $c + -1**$c*rvals($x)*$c) *
cos(-1**$x*$c - -1**$x*sin($x*$c) - -1**$c*rvals($x)*$c * 2*O*$c)
z = sin(-1**$x*$c - -1**$x*sin($x*$c) - -1**$c*rvals($x)*$c) *
sin(-1**$x*$c - -1**$x*sin($x*$c) - -1**$c*rvals($x)*$c * 2*O*$c)
So there are some ways here to look at this and make this hyper-realistic piddle
more accurate by adding in [time] and [phase] values in there proper positions
for a accurate simulation of a electron and its electric and magnetic field frequency's
and phase. The $r $g and $b seem to indicate moments,that theoretically I like to think
of as quanta color charges ...
-Mark R Baker
------------------------------------
unpack the module source then build:
Joe Milosch, also known as zentara on perlmonks, assembled this document.
Matthew Kenworthy, for the PDL NewBook and the TriD authors for the module