Exemplo n.º 1
0
r = size * 1.0
exponent = 1.0 / 2.0  # run with exponent=1 to get a physically correct version

doc = FieldplotDocument('naughty-solenoid')
field = Field({'coils': [[0, 0, 0, r, l, 1]]})
n = 15
for i in range(n):
    a = (0.5 + i) / n
    a = (-1. + 2. * a)
    # ... after this, a ranges approximately from -1 to 1
    a = copysign(abs(a)**exponent, a)
    # unphysical version for pedagogical use, students explain why it's impossible
    # makes field more intense near the walls
    # re copysign, see https://stackoverflow.com/questions/1986152/why-doesnt-python-have-a-sign-function
    a = a * size
    line = FieldLine(field, [0.0, a], directions='both', maxr=15.0)
    doc.draw_line(line, arrows_style={'dist': 3, 'offsets': [0., .5, .5, 1.]})
doc.draw_object(
    'path', {
        'style': 'fill:none; stroke:#808080; ' +
        'stroke-width:.06; stroke-linecap:butt',
        'd': f'M -{l},-{r} L {l},-{r}'
    })
doc.draw_object(
    'path', {
        'style': 'fill:none; stroke:#808080; ' +
        'stroke-width:.06; stroke-linecap:butt',
        'd': f'M -{l},{r} L {l},{r}'
    })
doc.write()
Exemplo n.º 2
0
#!/usr/bin/python3

# This is based on the code snippet at https://commons.wikimedia.org/wiki/File:VFPt_dipole.svg .

from math import *
from vectorfieldplot import FieldplotDocument,Field,FieldLine
# ... https://github.com/CD3/VectorFieldPlot

import logging
logging.basicConfig(level=logging.ERROR) # can be DEBUG, INFO, WARNING, or ERROR


doc = FieldplotDocument('dipole', width=800, height=600, commons=True)
k=1 # 3 for first panel
field = Field({'dipoles':[[k,0,1,0]]})
n = 16
for i in range(n):
    a = 2.0 * pi * (0.5 + i) / n
    line = FieldLine(field, [1+k+cos(a), sin(a)],
        maxr=1000, directions='both', pass_dipoles=0)
    doc.draw_line(line, arrows_style=None)
doc.write()
Exemplo n.º 3
0
#    spacing at left side is disrupted by extra lines; if too big, disrupted by missing lines
# Presumably this is because the software uses some units for I and B; if it was SI, then I would
# expect this to be 0.5e-7...?
for i in range(m):
    q = (i - m / 2.0) * 2.0 / m  # ranges from -1 to 1
    y = q * h
    r = abs(y) + 1.0e-6
    if y > 0.0:
        s = 1.0
    else:
        s = -1.0
    aa = a / f
    nn = (a * r + s * log(r)) / spacing
    if floor(nn) > floor(last_nn) and not (y > -1.0 / aa and y < 0.0) and not (
            y < 0.0 or y > 0.225 / aa):
        # ... 2nd clause is to avoid drawing the closed lines twice, 3rd is to avoid drawing lines that aren't closed
        print("y=", y, ", nn=", nn)
        line = FieldLine(field, [0, y], directions='both')
        doc.draw_line(line,
                      linewidth=1,
                      linecolor='#ff0000',
                      arrows_style=None)
    last_nn = nn
n = 20
for i in range(n):
    q = (i - n / 2.0) * 2.0 / n  # ranges from -1 to 1
    y = q * h
    line = FieldLine(field, [-2.9, y], directions='both')
    doc.draw_line(line, linewidth=4, arrows_style=None)
doc.write()
Exemplo n.º 4
0
#!/usr/bin/python3
from math import *
from vectorfieldplot import FieldplotDocument, Field, FieldLine
# ... https://github.com/CD3/VectorFieldPlot

print("generating file field-lines.svg")

# paste this code at the end of VectorFieldPlot 1.0
doc = FieldplotDocument('field-lines', width=800, height=800)
field = Field({'monopoles': [[0, -1, 1], [0, 1, -1]]})
n = 16
for i in range(n):
    a = (0.5 + i) / n
    a = 2.0 * pi * a
    line = FieldLine(field, [0, -1],
                     start_v=[cos(a), sin(a)],
                     directions='forward')
    doc.draw_line(line)
doc.write()
Exemplo n.º 5
0
#!/usr/bin/python3
from math import *
from vectorfieldplot import FieldplotDocument,Field,FieldLine
# ... https://github.com/CD3/VectorFieldPlot

print("generating files u.svg, like charges")

# paste this code at the end of VectorFieldPlot 1.0
doc = FieldplotDocument('u', width=800, height=800)
field = Field({'monopoles':[[-1,0,-1], [1,0,-1]]})
doc.draw_charges(field)
for x in [-1, 1]:
    line = FieldLine(field, [x,0], start_v=[x, 0],
        directions='backward')
    doc.draw_line(line)
n = 32
for i in range(n):
    a = 2.0 * pi * (0.5 + i) / n
    line = FieldLine(field, [10.*cos(a), 10.*sin(a)],
        directions='forward')
    doc.draw_line(line)
doc.write()

print("generating files v.svg, opposite charges")

# paste this code at the end of VectorFieldPlot 1.0
doc = FieldplotDocument('v', width=800, height=800)
field = Field({'monopoles':[[-1,0,1], [1,0,-1]]})
doc.draw_charges(field)
n = 16
for i in range(n):
Exemplo n.º 6
0
    'homogeneous': [field_direction],
    'dipoles': [[
        0, 0, 4 * pi * ball_radius**3 * field_direction[0],
        4 * pi * ball_radius**3 * field_direction[1]
    ]]
})
n = 20
for i in range(n):
    a = -3 + 6 * (0.5 + i) / n
    line = FieldLine(field, [a * scale, 6 * scale], maxr=12, pass_dipoles=1)
    if abs((n - 1.) / 2. - i) > 7: off = 4 * [0.5]
    else: off = 4 * [0.25]
    doc.draw_line(line,
                  arrows_style={
                      'min_arrows': 2,
                      'max_arrows': 2,
                      'offsets': off,
                      'scale': 2.0
                  })
# draw the superconducting ball
ball = doc.draw_object('g', {'id': 'metal_ball'})
grad = doc.draw_object('radialGradient', {
    'id': 'metal_spot',
    'cx': '0.53',
    'cy': '0.54',
    'r': '0.55',
    'fx': '0.65',
    'fy': '0.7',
    'gradientUnits': 'objectBoundingBox'
},
                       group=ball)
Exemplo n.º 7
0
Arquivo: draw.py Projeto: dzc0d3r/lm
first_sphere = True
for xys in [xy0, xy1]:
    for i in range(n):
        if first_sphere and i >= n / 2:
            continue
        displ = R * (2 * (i + 0.5) / n - 1) * math.sqrt(0.5)
        p0 = (displ, -displ) + xys
        line = FieldLine(field,
                         p0,
                         directions='both',
                         maxr=7,
                         path_close_tol=0.2,
                         hmax=0.1)
        doc.draw_line(line,
                      arrows_style={
                          'dist': 1.8,
                          'max_arrows': 2,
                          'offsets': [0.9, 0.3, 0.3, 0.9]
                      })
    first_sphere = False

# draw the spherical magnets
defs = doc.draw_object('defs', {})
grad = doc.draw_object('radialGradient', {
    'id': 'grad',
    'r': str(1.2 * R),
    'cx': '0',
    'cy': str(0.2 * R),
    'fx': '0',
    'fy': str(0.6 * R),
    'gradientUnits': 'userSpaceOnUse'
},