Skip to content

Instantly share code, notes, and snippets.

@bvancil
Created June 15, 2013 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bvancil/5789177 to your computer and use it in GitHub Desktop.
Save bvancil/5789177 to your computer and use it in GitHub Desktop.
Electric flux
{"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}
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()
scene.forward = vec(-13,2.2684953747456,1.936)
scene.fov= 0.400919887872002
// Originally from http://tributary.io/inlet/5593124
// 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: vec(1,1,1).multiply(2*0.05*L)} )
//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 = norm(obs).multiply(k*q/mag2(obs))
arrow( {pos:obs, axis_and_length:E.multiply(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") // scroll down for this
//$('body').append('<p>Flux='+Flux+'Vm</p')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment