from visual import *

print """
Right button drag to rotate view.
Left button drag up or down to move in or out.
"""
scene.title = "Magnetic field due to a current loop"
scene.center = vector(0,0,0)
scene.lights = [vector(0.5,0.5,0.5)]
scene.ambient = 0.3

radius = 0.5
ring(pos=(0,0,0),axis=(0,0,1),radius=radius,thickness=0.01,color=(1,0,0))

dtheta = 2.*pi/20.
max = 5.
scale = 0.01
for i in arange(-max,max+1,1.):
   for j in arange(-max,max+1,1.):
      for k in arange(-max,max+1,1.):
         bx = 0.
         by = 0.
         bz = 0.
         for theta in arange(0,2.*pi,dtheta):
            dlx = -radius*dtheta*sin(theta)
            dly = radius*dtheta*cos(theta)      
            rx = i/max-radius*cos(theta)
            ry = j/max-radius*sin(theta)
            rz = k/max 
            r = sqrt(rx**2+ry**2+rz**2)
            bx = bx+dly*rz/r**3
            by = by-dlx*rz/r**3
            bz = bz+(dlx*ry-dly*rx)/r**3
         arrow(pos=(i/max,j/max,k/max),axis=(scale*bx,scale*by,scale*bz),shaftwidth=0.02)
