Magnetic Induction - Coils

From GeoMod

Jump to: navigation, search

Program that shows the movement of a magnet through a wire coil, or a wire coil around a magnet, which creates a magnetic field (not shown yet).

Note:

  • l_move_coil = True ; will move the coil,
  • l_move_magnet = True ; will move the magnet.


from visual import *
import subprocess

def take_screenshot(fnum):
    fnum = str(fnum).zfill(3)
    fname = "img-"+fnum+".png"
    print fname
    cmd = ["screencapture", "-S", fname]
    test = subprocess.Popen( cmd, stdout=subprocess.PIPE).communicate()[0]


coil = frame()
spring = helix(frame=coil, pos=(-2.5,0,0), axis=(5.,0,0), radius=1, coils=5.5, thickness=0.1)
spring.color = color.yellow
spring.material = materials.emissive

wire1 = curve(frame=coil, pos=[(-2.5,0,1),(-2.5,-5,0)], radius=0.05)
wire1.color = spring.color
wire1.material = spring.material

wire2 = curve(frame=coil, pos=[(2.5,0,-1),(2.5,-5,0)], radius=0.05)
wire2.color = spring.color
wire2.material = spring.material

magnet = frame()
bar = box(frame=magnet, color=color.red, length=4, width=0.5, height = 1)
N = text(frame=magnet, pos=(bar.length*0.35,-0.2,bar.width/2.0), color=color.white, text="N")
N.height = bar.height*0.4
S = text(frame=magnet, pos=(-N.pos.x,N.pos.y,N.pos.z), color=color.white, text="S")
S.height = N.height

#magnet.pos = vector(-2,0,0)

l_move_coil = False
if l_move_coil:
    coil.pos = vector(-2,0,0)
l_move_magnet = True
if l_move_magnet:
    magnet.pos = vector(-2,0,0)

dx = 0.1
ct = 0


while 1:
#for i in range(int(7.5/dx)):
    ct+=1
    #take_screenshot(ct)
    rate(10)
    if l_move_magnet:
        magnet.pos.x += dx
        if magnet.pos.x >= 2.0:
            dx *= -1.0
            magnet.pos.x = 2.0
        elif magnet.pos.x <= -2.0:
            dx *= -1.0
            magnet.pos.x = -2.0
    if l_move_coil:
        coil.pos.x += dx
        if coil.pos.x >= 2.0:
            dx *= -1.0
            coil.pos.x = 2.0
        elif coil.pos.x <= -2.0:
            dx *= -1.0
            coil.pos.x = -2.0
        

Personal tools