# paste this code at the end of VectorFieldPlot 3.3
doc = FieldplotDocument('VFPt_sphere-magnet-inside', commons=True,
width=600, height=600)
x0, y0 = 0.0, 0.0
R = 1.0
dipole_field = Field([ 'dipole', {'x':0, 'y':0, 'px':0, 'py':1}] ])
def spheremagnet_F(xy):
r = xy - sc.array((x0, y0))
if vabs(r) < R:
# inside the field is indeed constant
return dipole_field.F(sc.array((0, R)))
else:
# outside the field is exatly that of a point-dipole
return dipole_field.F(r)
field = Field([ 'custom', {'F':spheremagnet_F}] ])
nlines = 18
for iline in range(nlines):
p0 = (R * (2 * (iline + 0.5) / nlines - 1), 0.)
line = FieldLine(field, p0, directions='both', maxr=7)
doc.draw_line(line, arrows_style={'scale':1.2, 'at_potentials':[0],
'potential':lambda xy: xy1 * (vabs(xy) - 2.3)})
# draw the spherical magnet
g = doc.draw_object('g', {'id':'sphere',
'transform':'translate({},{})'.format(x0, y0)}, bg=True)
doc.draw_object('circle', {'cx':'0', 'cy':'0', 'r':str(R),
'style':'fill:#80e680; stroke:none;'}, group=g)
doc.draw_object('path', {'d':'M -1,0 A 1,1 0 0 0 1,0 L -1,0 Z',
'style':'fill:#ff8080; stroke:none;'}, group=g)
doc.draw_object('circle', {'cx':'0', 'cy':'0', 'r':str(R),
'style':'fill:none; stroke:#000000; stroke-width:0.04;'}, group=g)
doc.write()