Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Physical simulations SL_Electron_Dynamics  

SL_Electron_Dynamics

This script has been working sporadically - use at your own risk.

Category: Physical simulations
By : Daniel C. Smith
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for SL_Electron_Dynamics
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. SL_Electron_Dynamics_1.lsl
1 //=============================================================
2 //SL Electron Dynamics, 0.1
3 //Demonstrates the movement of an electron through a magnetic field //Copyright (C) 2006 Daniel C. Smith //=============================================================
4
5 //GNU LICENSE ===============
6 //This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. See: http://www.gnu.org/licenses/licenses.html
7 //============================
8
9 // This script is very rough. Use at your own risk!
10
11 // Instructions:
12 //==============
13 // Just place script in an object (with physics turned off!) and touch the object. Any nonphysical object
14 // will do. I usually just use a sphere to represent an electron (or any charged particle).
15 // The default setting is a constant magnetic field pointing in the z direction, so the "electron" just
16 // travels in a circle.
17 // You can change the initial velocity (v), charge (q), and mass (m) of the "electron."
18 // You can also change the magnetic field (b). For now I have only implemented a constant mangetic
19 // field (constant in space and time).
20
21 // To do:
22 //=======
23 // - Make magnetic field variable in space and time.
24 // - Make magnetic field readable from an external source.
25 // - Add force due to electric field.
26
27 //SETTING UP THE OBJECT ===============
28
29 vector v; // velocity
30 vector x; // position
31 vector k0;
32 vector k1;
33 //vector k2;
34 //vector k3;
35 vector b = <0.0, 0.0, 1.0>; // magnetic field
36 float q = -1.0; // charge
37 float m = 1.0; // mass
38 float dt; // timestep
39
40 default
41 {
43 {
44 v = <0.0, 0.0, 0.0>;
45 x = llGetPos();
46 }
47
48 on_rez(integer start_param)
49 {
50 llOwnerSay("Rezzing.");
52 }
53
54 touch_start(integer total_number)
55 {
56 //llSay(0, "Tally ho!");
57 v = <1.0, 0.0, 0.0>; // Give an initial velocity.
58 state move;
59 }
60 }
61
62 state move
63 {
65 {
66 llSetTimerEvent(0.02);
67 }
68
69 timer()
70 {
71 // This is a 2nd (or 4th) order Runge-Kutta solver.
72 dt = 0.2;
73 x = x + v*dt; // Calculate new position.
74 llSetPos(x); // Send to new position.
75 //llOwnerSay((string) x.z);
76 // Calculate terms for Runge-Kutta solver:
77 k0 = dt*(q/m)*v%b;
78 k1 = dt*(q/m)*(v + 0.5*k0)%b;
79 //k2 = dt*(q/m)*(v + 0.5*k1)%b;
80 //k3 = dt*(q/m)*(v + k2)%b;
81 v = v + k1; // Calculate new velocity (2nd order).
82 //v = v + (k0 + 2*k1 + 2*k2 + k3)/6.0; // (4th order).
83 //llOwnerSay((string) llVecMag(v)); // Print the speed.
84 // Rinse. Lather. Repeat.
85 }
86
87 touch_start(integer total_number)
88 {
89 state default; // Stop moving.
90 }
91
92 on_rez(integer start_param)
93 {
94 llOwnerSay("Rezzing.");
96 }
97
99 {
100 llSay(0, "Stopping.");
101 }
102 }
103 //=============================================================

Back to the Best Free Tools in Second Life and OpenSim.