<s> from visual import * <EOL> scene . width = <NUM_LIT> <EOL> scene . height = <NUM_LIT> <EOL> scene . title = "<STR_LIT>" <EOL> scene . minscale = <NUM_LIT> <EOL> bigradius = <NUM_LIT> <EOL> smallradius = <NUM_LIT> <EOL> I = <NUM_LIT:1.> <EOL> muthing = <NUM_LIT> <EOL> nturns = <NUM_LIT> <EOL> nsteps = <NUM_LIT> <EOL> Bideal = muthing * <NUM_LIT> * nturns * I / bigradius <EOL> bscale = bigradius / ( Bideal * <NUM_LIT> ) <EOL> toroid = curve ( color = ( <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> ) , radius = <NUM_LIT> ) <EOL> tr = vector ( bigradius , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> dtheta = <NUM_LIT:2> * pi / ( nsteps * nturns ) <EOL> phi = <NUM_LIT:2> * pi / nsteps <EOL> a = arrow ( pos = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , axis = tr , visible = <NUM_LIT:0> ) <EOL> b = arrow ( pos = a . axis , axis = ( smallradius , <NUM_LIT:0> , <NUM_LIT:0> ) , visible = <NUM_LIT:0> ) <EOL> zaxis = vector ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> ocount = ( nsteps * nturns / <NUM_LIT> ) <EOL> Barrows = [ ] <EOL> for t in arange ( <NUM_LIT:0> , nsteps * nturns + <NUM_LIT:1> ) : <EOL> a . rotate ( angle = dtheta , axis = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> b . rotate ( angle = phi , axis = cross ( zaxis , a . axis ) ) <EOL> toroid . append ( pos = a . axis + b . axis ) <EOL> ocount = ocount + <NUM_LIT:1> <EOL> if ocount > ( nsteps * nturns / <NUM_LIT> ) : <EOL> ocount = <NUM_LIT:0> <EOL> c = arrow ( pos = <NUM_LIT> * a . axis , axis = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , color = ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:1> ) , shaftwidth = <NUM_LIT> ) <EOL> Barrows . append ( c ) <EOL> c = arrow ( pos = <NUM_LIT> * a . axis , axis = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , color = ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:1> ) , shaftwidth = <NUM_LIT> ) <EOL> Barrows . append ( c ) <EOL> c = arrow ( pos = a . axis , axis = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , color = ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:1> ) , shaftwidth = <NUM_LIT> ) <EOL> Barrows . append ( c ) <EOL> c = arrow ( pos = <NUM_LIT> * a . axis , axis = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , color = ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:1> ) , shaftwidth = <NUM_LIT> ) <EOL> Barrows . append ( c ) <EOL> c = arrow ( pos = <NUM_LIT> * a . axis , axis = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , color = ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:1> ) , shaftwidth = <NUM_LIT> ) <EOL> Barrows . append ( c ) <EOL> dlarrow = arrow ( pos = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , axis = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , color = ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) , shaftwidth = <NUM_LIT> ) <EOL> oldpt = toroid . pos [ <NUM_LIT:0> ] <EOL> for pt in toroid . pos : <EOL> rate ( <NUM_LIT> ) <EOL> dl = vector ( pt - oldpt ) <EOL> source = oldpt + dl / <NUM_LIT> <EOL> dlarrow . axis = dl * <NUM_LIT:2> <EOL> dlarrow . pos = source <EOL> for b in Barrows : <EOL> r = vector ( b . pos - source ) <EOL> dB = muthing * I * cross ( dl , r ) / r . mag ** <NUM_LIT:3> <EOL> b . axis = b . axis + dB * bscale <EOL> oldpt = pt <EOL> dlarrow . visible = <NUM_LIT:0> <EOL> print ( "<STR_LIT>" , Barrows [ <NUM_LIT:2> ] . axis . mag / bscale ) <EOL> print ( "<STR_LIT>" , Bideal ) </s>
