We don't bite newbies here... much PerlMonks

### PDL 3d TriD animation of the electron

by zentara (Archbishop)
 on Apr 06, 2012 at 12:01 UTC ( #963819=CUFP: print w/replies, xml ) Need Help??

Hi, here is an animated electron simulation crafted by Mark Baker, who is an active PDL user. screenshot

It is posted with his consent in the hope of stimulating students to look into math and physics.

```#!/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 con
+cern...

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 Obser
+vatory
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 [e
+q.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]

\$q=\$i*\$n;

points3d[ \$b*sin(\$q), \$r*cos(\$q), \$g*sin(\$q)], [\$g,\$b,\$r] } ## furt
+her transformation that makes every thing work

=cut

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re: PDL 3d TriD animation of the electron
by syphilis (Chancellor) on Apr 07, 2012 at 09:26 UTC
What a great little demo !
It works well on MS Windows, too (best viewed as "full screen") - apart from some inconsequential warnings/errors (from freeglut) that are displayed to the console when the TriD graphics window is closed and the script exits:
```freeglut (electron.pl): glutSetWindow(): window ID 1 not found!
freeglut (electron.pl):  ERROR:  Function <glutSwapBuffers> called wit
+h no current window defined.
Cheers,
Rob

Create A New User
Node Status?
node history
Node Type: CUFP [id://963819]
Approved by ww
Front-paged by Corion
help
Chatterbox?
 [Discipulus]: a possibly good morning to you all monks!

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-06-26 08:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How many monitors do you use while coding?

Results (573 votes). Check out past polls.