# pegue este código al final de VectorFieldPlot 2.5 R = 0.6 h = 0.6 rsym = 21doc = FieldplotDocument ( 'VFPt_dipoles_magnetic1' , commons = True , width = 360 , height = 360 ) field = Field ([ [ 'dipole' , { 'x' : 0 , 'y' : 0 , 'px' : 0. , 'py' : 1. }] ])def f_arrows ( xy ): return xy [ 1 ] * ( sc . hypot ( xy [ 0 ], xy [ 1 ]) / 1.4 - 1 ) def f_cond ( xy ): return hypot ( * xy ) > 1e-4 y ( fabs ( xy [ 1 ]) < 1e-3 o fabs ( xy [ 1 ]) > . 3 )nlines = 19 puntos de inicio = Ruta de inicio ( campo , lambda t : 0.25 * sc . matriz ([ sin ( t ), cos ( t )]), t0 = - pi / 2 , t1 = pi / 2 ) . NPOINTS ( nLines ) para p0 en startpoints : línea = Fieldline ( campo , p0 , direcciones = 'ambos' ) doc . draw_line ( línea , maxdist = 1 , arrow_style = { 'at_potentials' : [ 0. ], 'potencial' : f_arrows , 'condition_func' : f_cond , 'scale' : 1.2 })# dibuja el símbolo dipolo rg_grad = etree . SubElemento ( doc . _Get_defs (), 'linearGradient' ) rg_grad . set ( 'id' , 'grad_rg' ) para attr , val en [ [ 'x1' , '0' ], [ 'x2' , '0' ], [ 'y1' , '0' ], [ 'y2' , '1' ] ]: rg_grad . set ( attr , val ) para col , de en [ [ '# 00cc00' , '0' ], [ '# 887744' , '0.5' ], [ '# ff0000' , '1' ] ]: stop = etree . SubElement ( rg_grad , 'stop' ) detener . set ( 'stop-color' , col ) stop . set ( 'offset' , of ) stop . set ( 'stop-opacity' , '1' ) symb = doc . draw_object ( 'g' , { 'id' : 'dipole_symbol' , 'transform' : 'scale ( {0} , {0} )' . format ( 1. / doc . unit )}) doc . draw_object ( 'circle' , { 'cx' : '0' , 'cy' : '0' , 'r' : rsym , 'fill' : 'url (#grad_rg)' , 'stroke' : 'none' }, grupo = simb ) doc . _check_whitespot () doc . draw_object ( 'circle' , { 'cx' : '0' , 'cy' : '0' , 'r' : rsym , 'fill' : 'url (#white_spot)' , 'stroke' : '# 000000' , 'trazo-ancho' : '3' }, grupo = simb ) doc . draw_object ( 'path' , { 'fill' : '# 000000' , 'stroke' : 'none' , 'd' : 'M 3, -12 V 0 H 12 L 0,15 L -12,0 H -3 V -12 H 3 Z ' }, grupo = simb ) doc . escribir ()doc = FieldplotDocument ( 'VFPt_dipoles_magnetic2' , commons = True , width = 360 , height = 360 ) field = Field ([ [ 'monopolo' , { 'x' : 0 , 'y' : h , 'Q' : 1 }] , [ 'monopolo' , { 'x' : 0 , 'y' : - h , 'Q' : - 1 }] ])def f_arrows ( xy ): return xy [ 1 ] * ( sc . hypot ( xy [ 0 ], xy [ 1 ]) / 1.4 - 1 ) def f_cond ( xy ): return fabs ( xy [ 0 ]) < 1.4nlines = 18 stp = Startpath ( field , lambda t : R * sc . array ([ . 2 * sin ( t ), 1 +. 2 * cos ( t )]), t0 = - pi , t1 = pi ) puntos de inicio = [ stp . startpos ( s ) para s en sc . arange ( nLines ) / flotador ( nLines )] startpoints . append ( startpoints [ nLines // 2 ] . dot ([ [ 1 , 0 ], [ 0 , - 1 ] ])) para p0 en startpoints : línea = Fieldline ( campo , p0 , direcciones = 'ambos' , MaxR = 100 ) doc . draw_line ( línea , maxdist = 1 , arrow_style = { 'at_potentials' : [ 0. ], 'potencial' : f_arrows , 'condition_func' : f_cond , 'scale' : 1.2 })# dibujar símbolos de polos symb_N = doc . draw_object ( 'g' , { 'id' : 'north_symbol' , 'transform' : 'translate (0, {0} ) scale ( {1} , {1} )' . format ( h , 1. / doc . unit )}) symb_S = doc . draw_object ( 'g' , { 'id' : 'south_symbol' , 'transform' : 'translate (0, {0} ) scale ( {1} , {1} )' . format ( - h , 1. / doc . unit )}) para i , g en enumerate ([ symb_N , symb_S ]): doc . draw_object ( 'circle' , { 'cx' : '0' , 'cy' : '0' , 'r' : rsym , 'stroke' : 'none' , 'fill' : [ '# ff0000' , '# 00cc00 ' ] [ i ]}, grupo = g ) doc . _check_whitespot () doc . draw_object ( 'circle' , { 'cx' : '0' , 'cy' : '0' , 'r' : rsym , 'fill' : 'url (#white_spot)' , 'stroke' : '# 000000' , 'trazo-ancho' : '3' }, grupo = g ) texto = etree . SubElement ( g , 'text' ) para attr , val en [ [ 'text-anchor' , 'middle' ], [ 'x' , 0 ], [ 'y' , 11 ], [ 'fill' , '# 000000 ' ], [ ' stroke ' , ' none ' ], [ ' font-size ' , ' 32px ' ], [ ' font-family ' , ' Bitstream Vera Sans ' ], [ ' transform ' , ' scale (1, - 1) ' ] ]: texto . set ( attr , str ( val )) texto . texto = [ 'N' , 'S' ] [ i ] doc . escribir ()doc = FieldplotDocument ( 'VFPt_dipoles_magnetic3' , commons = True , width = 360 , height = 360 ) field = Field ([ [ 'ringcurrent' , { 'x' : 0 , 'y' : 0 , 'R' : R , ' phi ' : pi / 2 , ' I ' : 1. }] ])def f_arrows ( xy ): return xy [ 1 ] * ( sc . hypot ( xy [ 0 ], xy [ 1 ]) / 1.4 - 1 ) def f_cond ( xy ): return hypot ( * xy ) > R y fabs ( fabs ( xy [ 0 ]) - 1,4 ) > 0,2nlines = 13 puntos de inicio = Ruta de inicio ( campo , lambda t : matriz sc . ([ R * t , 0. ]), t0 = - 0.8 , t1 = 0.8 ) . NPOINTS ( nLines ) para p0 en startpoints : línea = Fieldline ( campo , p0 , direcciones = 'ambos' ) doc . draw_line ( línea , maxdist = 1 , arrow_style = { 'at_potentials' : [ 0. ], 'potencial' : f_arrows , 'condition_func' : f_cond , 'scale' : 1.2 }) # dibujar símbolos actuales symb_out = doc . draw_object ( 'g' , { 'id' : 'out_symbol' , 'transform' : 'translate ( {0} , 0) scale ( {1} , {1} )' . format ( - R , 1. / doc . unidad )}) symb_in = doc . draw_object ( 'g' , { 'id' : 'in_symbol' , 'transform' : 'translate ( {0} , 0) scale ( {1} , {1} )' . format ( R , 1. / doc . unit )}) para i , g en enumerate ([ symb_out , symb_in ]): doc . draw_object ( 'circle' , { 'cx' : '0' , 'cy' : '0' , 'r' : rsym , 'stroke' : 'none' , 'fill' : '# 999999' }, group = g ) doc . _check_whitespot () doc . draw_object ( 'circle' , { 'cx' : '0' , 'cy' : '0' , 'r' : rsym , 'fill' : 'url (#white_spot)' , 'stroke' : '# 000000' , 'trazo-ancho' : '3' }, grupo = g ) si i == 0 : # punto c_symb = etree . SubElemento ( g , 'círculo' ) c_symb . set ( 'cx' , '0' ) c_symb . set ( 'cy' , '0' ) c_symb . set ( 'r' , '6' ) else : # cross c_symb = etree . SubElemento ( g , 'ruta' ) c_symb . conjunto ( 'd' , 'M {1} , {4} L {0} , {5} L {2} , {3} L {0} , {1} \ L {1} , {0} {3 } , {2} L {5} , {0} L {4} , {1} L {6} , {3} L {4} , {5} L {5} , {4} \ L {3} , {6} L {1} , {4} Z ' . Formato ( 12.24 , 8 , 4.24 , 0 , - 12.24 , - 8 , - 4.24 )) c_symb . set ( 'estilo' , 'relleno: # 000000; trazo: ninguno' ) doc . escribir () doc = FieldplotDocument ( 'VFPt_dipoles_magnetic4' , commons = True , width = 360 , height = 360 ) field = Field ([ [ 'coil' , { 'x' : 0 , 'y' : 0 , 'phi' : pi / 2 , 'R' : R , 'Lhalf' : h , 'I' : 1. }] ])def f_arrows ( xy ): return xy [ 1 ] * ( sc . hypot ( xy [ 0 ], xy [ 1 ]) / 1.4 - 1 ) def f_cond ( xy ): return sc . hipot ( xy [ 0 ], xy [ 1 ]) > Rnlines = 13 para iline en rango ( nlines ): p0 = sc . array ([ R * ( - 1. + 2. * ( iline + 0.5 ) / nlines ), 0. ]) línea = FieldLine ( campo , p0 , direcciones = 'ambos' , maxr = 100 ) doc . draw_line ( línea , maxdist = 1 , arrow_style = { 'at_potentials' : [ 0. ], 'potencial' : f_arrows , 'condition_func' : f_cond , 'scale' : 1.2 })# dibujar solenoide sheet_out = doc . draw_object ( 'g' , { 'transform' : 'translate ( {0} , 0)' . format ( - R )}) sheet_in = doc . draw_object ( 'g' , { 'transform' : 'translate ( {0} , 0)' . format ( R )}) for i , g in enumerate ([ sheet_out , sheet_in ]): doc . draw_object ( 'rect' , { 'stroke-width' : 0.03 , 'stroke-linejoin' : 'round' , 'x' : - 0.045 , 'y' : - h , 'width' : 0.09 , 'height' : 2 * h , 'stroke' : '# 000000' , 'fill' : '#bbbbbb' }, group = g ) nsym = 12 para isym en rango ( nsym ): y = ( h - 0.015 ) * ( 2 * ( isym + 0.5 ) / nsym - 1 ) si i == 0 : doc . draw_object ( 'circle' , { 'cx' : '0' , 'cy' : y , 'r' : 0.02 , 'fill' : '# 000000' , 'stroke' : 'none' }, group = g ) else : doc . dibujar_objeto ( 'ruta' , { 'd' : 'M -2, -2 L 2,2 M -2,2 L 2, -2' , 'llenar' : 'ninguno' , 'trazo' : '# 000000' , 'transform' : 'translate (0, {0} ) scale (0.012)' . format ( y ), 'stroke-width' : '1' , 'stroke-linecap' : 'butt' }, group = g ) doc . escribir ()