[ Launch: Bee in Browser ] 5784493 by bvancil
[ Launch: Glowscript? ] 5593124 by elsherbini
-
-
Save bvancil/5784493 to your computer and use it in GitHub Desktop.
Electric flux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"description":"Electric flux","endpoint":"","display":"div","public":true,"require":[{"name":"glowscript","url":"https://bitbucket.org/davidscherer/glowscript/raw/8af3ac25a24e733367472159f7f2e1a0ca276dbc/package/glow.1.0.min.js"},{"name":"compiler","url":"https://bitbucket.org/davidscherer/glowscript/raw/8af3ac25a24e733367472159f7f2e1a0ca276dbc/package/compiler.1.0.min.js"},{"name":"symbols","url":"https://bitbucket.org/davidscherer/glowscript/raw/8af3ac25a24e733367472159f7f2e1a0ca276dbc/package/symbols.1.0.min.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var body = d3.select("#display"); | |
body.append("div") | |
.attr("id", "glowscript") | |
.attr("class", "glowscript") | |
.append("p") | |
.text("In GlowScript programs: Rotate the camera by dragging with the right mouse button. To zoom, drag with the left+right mouse buttons, or use the mouse wheel.") | |
.style("max-width", "726px"); | |
//You can change all the parameters in this section to see how it affects the output | |
window.__context = { glowscript_container: $("#glowscript").removeAttr("id") } | |
var scene = canvas(); | |
// Pasted from http://www.glowscript.org/#/user/Frank_Noschese/folder/My_Programs/program/Electric_flux_through_a_square/edit | |
// Converted from the VPython program BrilliantGaussLaw | |
//Constants | |
var q = 1e-9; //charge | |
var k = 9e9; //electrostatic constant | |
var L = 1.0; //length of square face | |
var dL = 0.2*L; //size of dA <-- CHANGE THIS TO MAKE FLUX MORE/LESS ACCURATE | |
//Objects | |
sphere ( {pos:vec(0,0,0), color:color.red, size:2*0.05*L*vec(1,1,1)} ); | |
//intitial conditions | |
var obs = vec(L,dL/2,dL/2); | |
var dFlux = 0; | |
var Flux = 0; | |
while (obs.z < L) { | |
obs.y = 0; | |
while (obs.y < L) { | |
box( {pos:obs, size:vec(0.01*L, dL, dL), color:color.green} ); | |
var E = k*q/mag2(obs)* norm(obs); | |
arrow( {pos:obs, axis_and_length:E*0.1, color:color.orange, shaftwidth:dL/5} ); | |
dFlux = E.x*dL*dL; | |
Flux = Flux + dFlux; | |
obs.y = obs.y + dL; | |
} | |
obs.z = obs.z + dL; | |
} | |
//print ("Flux =",Flux,"Vm"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment