GlowScript 3.0 VPython def EF_point(q,rq,r): ke=1. rrq=r-rq rrq0=mag(rrq) Es=ke*q/rrq0**2 E=ke*q*rrq/rrq0**3 return E,Es q=1.; rq=vec(0.,0.,0.) r1=vec(1,0,0) E1,E1s=EF_point(q,rq,r1) print(r1,'E1=',E1,' E1s=',E1s) r2=vec(1,0,1) E2,E2s=EF_point(q,rq,r2) print(r2,E2,E2s) r3=vec(1,1,1) E3,E3s=EF_point(q,rq,r3) print(r3,E3,E3s) scene=canvas(width=800, height=600, center=vector(1,1,0)) box(pos=vec(1,0,1),size=vec(2,0.01,3),color=vec(0,1,1),opacity=0.5) X=arrow(pos=vec(0,0,0),axis=vec(2,0,0),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,1)) Y=arrow(pos=vec(0,0,0),axis=vec(0,2,0),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,1)) Z=arrow(pos=vec(0,0,0),axis=vec(0,0,2),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,1)) Q1=sphere(pos=rq,radius=0.3,color=vec(1,1,0)) F1=sphere(pos=r1,radius=0.1,color=vec(1,1,1)) F2=sphere(pos=r2,radius=0.1,color=vec(1,1,1)) F3=sphere(pos=r3,radius=0.1,color=vec(1,1,1)) A1=arrow(pos=r1,axis=E1,shaftwidth=0.02,headwidth=0.04,color=vec(1,0,1)) A2=arrow(pos=r2,axis=E2,shaftwidth=0.02,headwidth=0.04,color=vec(1,0,1)) A3=arrow(pos=r3,axis=E3,shaftwidth=0.02,headwidth=0.04,color=vec(1,0,1))
GlowScript 3.0 VPython def EFV_point(q,rq,r): ke=1. rrq=r-rq rrq0=mag(rrq) Es=ke*q/rrq0**2 V=ke*q/rrq0 E=ke*q*rrq/rrq0**3 return E,Es,V q=1.; rq=vec(0.,0.,0.) N=20; dx=0.1 gd = graph(width=800, height=600, background=color.black, title='Electric field and potential of a point charge', xtitle='x', ytitle='E/V' ,xmin=0, xmax=2.2, ymin=0, ymax=10) f1 = gcurve(color=color.cyan, label="E(x)") f2 = gdots(color=color.green, label="V(x)") for i in range(N): x=dx*(i+1) r=vec(x,0,0) E,Es,V=EFV_point(q,rq,r) f1.plot(x,Es) f2.plot(x,V)
GlowScript 3.0 VPython def EFV_point(q,rq,r): ke=1. rrq=r-rq rrq0=mag(rrq) Es=ke*q/rrq0**2 V=ke*q/rrq0 E=ke*q*rrq/rrq0**3 return E,Es,V q1=1.; rq1=vec(0.,0.,0.) q2=1.; rq2=vec(4.,0.,0.) N=38; dx=0.1 scene=canvas(width=800, height=600, center=vector(2.5,1,0)) X=arrow(pos=vec(0,0,0),axis=vec(5,0,0),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,1)) Y=arrow(pos=vec(0,0,0),axis=vec(0,2,0),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,1)) Z=arrow(pos=vec(0,0,0),axis=vec(0,0,0.5),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,1)) Q1=sphere(pos=rq1,radius=0.1,color=vec(1,1,0)) Q2=sphere(pos=rq2,radius=0.1,color=vec(1,1,0)) s=0.1 gd = graph(width=800, height=600, background=color.black, title='Electric field 2 point charges at x=0 and x=4', xtitle='x', ytitle='E/V' ,xmin=0, xmax=4.2, ymin=0) f1 = gcurve(color=color.cyan, label="y=0.5") f2 = gcurve(color=color.green, label="y=1.0") for i in range(N): x=dx*(i+1) r1=vec(x,0.5,0) E1,Es1,V1=EFV_point(q1,rq1,r1) E2,Es2,V2=EFV_point(q2,rq2,r1) E=E1+E2 Es=mag(E) f1.plot(x,Es) arrow(pos=r1,axis=E*s,shaftwidth=0.02,headwidth=0.04,color=vec(1,0,1)) r2=vec(x,1.0,0) E1,Es1,V1=EFV_point(q1,rq1,r2) E2,Es2,V2=EFV_point(q2,rq2,r2) E=E1+E2 Es=mag(E) f2.plot(x,Es) arrow(pos=r2,axis=E*s,shaftwidth=0.02,headwidth=0.04,color=vec(1,0,1))
GlowScript 3.0 VPython def EFV_point(q,rq,r): ke=1. rrq=r-rq rrq0=mag(rrq) Es=ke*q/rrq0**2 V=ke*q/rrq0 E=ke*q*rrq/rrq0**3 return E,Es,V q0=1.; rq0=vec(0.,0.,0.) q1=1.; rq1=vec(-1,0.,0.) q2=-1; rq2=vec(1,0.,0.) N=200; dx=0.1 scene=canvas(width=800, height=600, center=vector(0,3,0)) X=arrow(pos=vec(-1.2,0,0),axis=vec(2.4,0,0),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,1)) Y=arrow(pos=vec(0,0,0),axis=vec(0,8,0),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,1)) Q0=sphere(pos=rq0,radius=0.1,color=vec(1,1,0)) Q1=sphere(pos=rq1,radius=0.1,color=vec(1,0,0)) Q2=sphere(pos=rq2,radius=0.1,color=vec(0,0,1)) gd = graph(width=800, height=600, background=color.black, title='Electric field 2 point charges at x=0 and x=4', xtitle='x', ytitle='E', ymax=0.1) # ,xmin=0, xmax=4.2, ymin=0) f1 = gcurve(color=color.cyan, label="only 1 q") f2 = gcurve(color=color.green, label="q and -q") for i in range(N): x=0.1+dx*(i) r=vec(0,x,0) E,Es,V=EFV_point(q0,rq0,r) Es1=mag(E) f1.plot(x,Es1) E1,Es1,V1=EFV_point(q1,rq1,r) E2,Es2,V2=EFV_point(q2,rq2,r) Ed=E1+E2 Es2=mag(Ed) f2.plot(x,Es2)
\(x=v\cos(\theta)t\) \(y=v\sin(\theta)t-\dfrac{1}{2} g t^2\) \(\tan(\theta)=\dfrac{y(0)}{x(0)}\) \(t=\dfrac{x}{v \cos(\theta)}\) \(y(x)=\tan(\theta)x-\dfrac{g}{2 v^2 \cos^2(\theta)} x^2\) \(m=\dfrac{dy}{dx}=\tan(\theta)-\dfrac{g}{ v^2 \cos^2(\theta)} x\) \(s^2=dx^2 + dy^2; \,\,\, dy=m dx\) \(dx=\sqrt{\dfrac{s^2}{1+m^2}}; \,\,\, dy=mdx\) \(\vec{r}'=\vec{r}+d\vec{r}; \,\,\, d\vec{r}=\rm{vec(dx,dy,0)}\) |
GlowScript 3.0 VPython def line(v,Ni,s,r1): r=1*r1; g=9.8; theta=atan(r.y/r.x) for i in range(Ni): m=tan(theta)-(g/(v*cos(theta))**2)*r.x dx=sqrt(s**2/(1+m**2)) dy=dx*m dr=vec(dx,dy,0) arrow(pos=r,axis=dr,shaftwidth=0.02,headlength=0.12,headwidth=0.12,color=vec(1,1,0)) r+=dr scene=canvas(width=800, height=600, center=vector(4,2,0)) Nj=5; Ni=20; s=0.4; v=10; R=s/4 Q1=sphere(pos=vec(0,0,0),radius=R,color=vec(1,0,0)) for j in range(Nj): deg=30+10*j t=radians(deg) r1=vec(cos(t),sin(t),0)*s line(v,Ni,s,r1)
GlowScript 3.0 VPython def EFV_point(q,rq,r): ke=1. rrq=r-rq rrq0=mag(rrq) Es=ke*q/rrq0**2 V=ke*q/rrq0 E=ke*q*rrq/rrq0**3 return E,Es,V def Eline(q1,rq1,r1): N=40; s=0.05 for i in range(N): E,Es,V=EFV_point(q1,rq1,r1) dr=hat(E)*s arrow(pos=r1,axis=dr,shaftwidth=0.02,headwidth=0.02,color=vec(1,1,1)) r1+=dr q1=1.; rq1=vec(0.,0.,0.); R=0.2 scene=canvas(width=800, height=600, center=vector(0,0,0)) X=arrow(pos=vec(0,0,0),axis=vec(2,0,0),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,0)) Y=arrow(pos=vec(0,0,0),axis=vec(0,2,0),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,0)) Z=arrow(pos=vec(0,0,0),axis=vec(0,0,2),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,0)) Q1=sphere(pos=rq1,radius=R,color=vec(1,0,0)) Nr=10 s=0.1; r1=vec(1,0,0) for jt in range(Nr): t=pi/Nr*jt for jf in range(Nr): f=2*pi/Nr*jf r1=R*vec(cos(f)*sin(t),sin(f)*sin(t),cos(t)) Eline(q1,rq1,r1)
GlowScript 3.0 VPython def EFV_point(q,rq,r): ke=1. rrq=r-rq rrq0=mag(rrq) Es=ke*q/rrq0**2 V=ke*q/rrq0 E=ke*q*rrq/rrq0**3 return E,Es,V def Eline(q1,rq1,q2,rq2,r1): N=40; s=0.05 for i in range(N): E1,Es1,V1=EFV_point(q1,rq1,r1) E2,Es2,V2=EFV_point(q2,rq2,r1) dr=hat(E1+E2)*s arrow(pos=r1,axis=dr,shaftwidth=0.02,headwidth=0.02) r1+=dr q1=1.; rq1=vec(0.,0.,0.); R=0.2 q2=-1.; rq2=vec(2.,0.,0.); scene=canvas(width=800, height=600, center=vector(0,0,0)) X=arrow(pos=vec(0,0,0),axis=vec(2,0,0),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,0)) Y=arrow(pos=vec(0,0,0),axis=vec(0,2,0),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,0)) Z=arrow(pos=vec(0,0,0),axis=vec(0,0,2),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,0)) Q1=sphere(pos=rq1,radius=R,color=vec(1,0,0)) Q2=sphere(pos=rq2,radius=R,color=vec(0,0,1)) Nr=10 s=0.1; r1=vec(1,0,0) for jt in range(Nr): t=pi/Nr*jt for jf in range(Nr): f=2*pi/Nr*jf r1=R*vec(cos(f)*sin(t),sin(f)*sin(t),cos(t)) Eline(q1,rq1,q2,rq2,r1)
GlowScript 3.0 VPython def EFV_point(q,rq,r): ke=1. rrq=r-rq rrq0=mag(rrq) Es=ke*q/rrq0**2 V=ke*q/rrq0 E=ke*q*rrq/rrq0**3 return E,Es,V def linesource(r): global NQ,q,L,dy E=vec(0,0,0) for i in range(NQ): rq=vec(0,-L/2+dy*i,0) Ei,Esi,Vi=EFV_point(q,rq,r) E+=Ei return E def Eline(r1): N=40; s=0.05 for i in range(N): E=linesource(r1) dr=hat(E)*s arrow(pos=r1,axis=dr,shaftwidth=0.02,headwidth=0.02) r1+=dr q1=1.; rq1=vec(0.,0.,0.); R=0.1 q2=-1.; rq2=vec(2.,0.,0.); scene=canvas(width=800, height=600, center=vector(0,0,0)) X=arrow(pos=vec(0,0,0),axis=vec(2,0,0),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,0)) Y=arrow(pos=vec(0,0,0),axis=vec(0,2,0),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,0)) Z=arrow(pos=vec(0,0,0),axis=vec(0,0,2),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,0)) NQ=21;q=1/NQ; L=8; dy=L/(NQ-1); E=vec(0,0,0) for i in range(NQ): rq=vec(0,-L/2+dy*i,0) sphere(pos=rq,radius=R,color=color.red) Nr=11 s=0.2; r1=vec(1,0,0) for jy in range(Nr): y=-5+1*jy for jf in range(Nr): f=2*pi/(Nr-1)*jf r1=vec(R*cos(f),y,R*sin(f)) Eline(r1)
GlowScript 3.0 VPython def EFV_point(q,rq,r): ke=1. rrq=r-rq rrq0=mag(rrq) Es=ke*q/rrq0**2 V=ke*q/rrq0 E=ke*q*rrq/rrq0**3 return E,Es,V def Eline(q1,rq1,r1): N=30; s=0.05 for i in range(N): E,Es,V=EFV_point(q1,rq1,r1) dr=hat(E)*s arrow(pos=r1,axis=dr,shaftwidth=0.02,headwidth=0.02,color=vec(1,1,1)) r1+=dr q1=1.; rq1=vec(0.,0.,0.); R=0.2; RG=R*10 scene=canvas(width=1000, height=800, center=vector(0,0,0)) X=arrow(pos=vec(0,0,0),axis=vec(2,0,0),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,0)) Y=arrow(pos=vec(0,0,0),axis=vec(0,2,0),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,0)) Z=arrow(pos=vec(0,0,0),axis=vec(0,0,2),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,0)) Q1=sphere(pos=rq1,radius=R,color=vec(1,0,0)) G=sphere(pos=rq1,radius=RG,color=vec(1,1,0), opacity=0.2) Nr=6; NA=Nr*Nr; dA=4*pi*RG**2/NA s=0.1; r1=vec(1,0,0); FLUX=0 for jt in range(Nr): t=pi/Nr*jt for jf in range(Nr): f=2*pi/Nr*jf r1=R*vec(cos(f)*sin(t),cos(t),sin(f)*sin(t)) Eline(q1,rq1,r1) rG=RG*vec(cos(f)*sin(t),cos(t),sin(f)*sin(t)) dS=hat(r1)*dA arrow(pos=rG,axis=dS*0.5,shaftwidth=0.04,headwidth=0.08,color=vec(0,0.5,1)) E,Es,V=EFV_point(q1,rq1,rG) FLUX+=dot(dS,E) print(NA,FLUX) # k=1; 1/(4 pi epsilon_0)=1; 1/epsilon_0=4pi; Gauss law:FLUX=Q/epsilon_0=4 pi Q=4 pi=12.566
GlowScript 3.0 VPython def EFV_point(q,rq,r): ke=1. rrq=r-rq rrq0=mag(rrq) Es=ke*q/rrq0**2 V=ke*q/rrq0 E=ke*q*rrq/rrq0**3 return E,Es,V def Eline(r1): N=30; s=0.1 for i in range(N): E1,Es1,V1=EFV_point(q1,rq1,r1) E2,Es2,V2=EFV_point(q2,rq2,r1) E=E1+E2 dr=hat(E)*s arrow(pos=r1,axis=dr,shaftwidth=0.02,headwidth=0.06,color=vec(1,1,1)) r1+=dr if(mag(r1) > 1): break global q1,rq1,q2,rq2 q1=1.; rq1=vec(-0.5,0.,0.); R=0.2; RG=R*10 q2=-1.; rq2=vec(0.5,0,0.) scene=canvas(width=1000, height=800, center=vector(0,0,0)) X=arrow(pos=vec(0,0,0),axis=vec(2,0,0),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,0)) Y=arrow(pos=vec(0,0,0),axis=vec(0,2,0),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,0)) Z=arrow(pos=vec(0,0,0),axis=vec(0,0,2),shaftwidth=0.02,headwidth=0.04,color=vec(1,1,0)) Q1=sphere(pos=rq1,radius=R,color=vec(1,0,0)) Q2=sphere(pos=rq2,radius=R,color=vec(0,0,1)) G=sphere(pos=vec(0,0,0),radius=RG,color=vec(1,1,0), opacity=0.2) Nr=6; NA=Nr*Nr; dA=4*pi*RG**2/NA s=0.1; r1=vec(1,0,0); FLUX=0 for jt in range(Nr): t=pi/Nr*jt for jf in range(Nr): f=2*pi/Nr*jf r1=9*R*vec(cos(f)*sin(t),cos(t),sin(f)*sin(t)) sphere(pos=r1,radius=0.3*R,color=vec(0,0,0)) Eline(r1) rG=RG*vec(cos(f)*sin(t),cos(t),sin(f)*sin(t)) dS=hat(r1)*dA arrow(pos=rG,axis=dS*0.5,shaftwidth=0.04,headwidth=0.08,color=vec(0,0.5,1)) E1,Es1,V1=EFV_point(q1,rq1,rG) E2,Es2,V2=EFV_point(q2,rq2,rG) E=E1+E2 arrow(pos=rG,axis=E*5,shaftwidth=0.04,headwidth=0.08,color=vec(1,0,0)) FLUX+=dot(dS,E) print(NA,FLUX) # k=1; 1/(4 pi epsilon_0)=1; 1/epsilon_0=4pi; Gauss law:FLUX=Q/epsilon_0=4 pi Q=4 pi=12.566