1 |
gezelter |
4407 |
#!/opt/local/bin/python2.7 |
2 |
|
|
|
3 |
|
|
'''An example script that generates a picture of the field lines for an electric field gradient.''' |
4 |
|
|
|
5 |
|
|
import math |
6 |
|
|
import VectorFieldPlot as vfp |
7 |
|
|
|
8 |
|
|
# create a document. we specify the file name and image size here |
9 |
|
|
doc = vfp.FieldplotDocument( 'Gradient', width=800,height=600,unit=100) |
10 |
|
|
|
11 |
|
|
# create a field opbject |
12 |
|
|
field = vfp.Field() |
13 |
|
|
# note, parameters are should be [ r_x, r_y, phi, q], where r is the position vector, phi is the angle of the quadrupole in radians, and q is the charge magnitude |
14 |
|
|
field.add_element('gradient' , [ [ 1.0, 1.0, 0.0, 0.0, 1.0 ] ]) |
15 |
|
|
|
16 |
|
|
# start drawing the field lines |
17 |
|
|
#bottom up |
18 |
|
|
N = 18 |
19 |
|
|
for i in range(N): |
20 |
|
|
x = -4 + 8 * float(i) / float(N) |
21 |
|
|
y = -3 |
22 |
|
|
# generate the line |
23 |
|
|
# this takes the initial position, the x and y components of the initial direction, and whether or not should go forward |
24 |
|
|
# or backward. |
25 |
|
|
line = vfp.FieldLine( field, [x, y], start_v=[0, 1],directions='forward' ) |
26 |
|
|
# draw the lin on the document |
27 |
|
|
doc.draw_line(line,arrows_style={'min_arrows':1,'scale':0.4,'max_arrows':3}) |
28 |
|
|
|
29 |
|
|
#top down |
30 |
|
|
for i in range(N): |
31 |
|
|
x = -4 + 8 * float(i) / float(N) |
32 |
|
|
y = 3 |
33 |
|
|
# generate the line |
34 |
|
|
# this takes the initial position, the x and y components of the initial direction, and whether or not should go forward |
35 |
|
|
# or backward. |
36 |
|
|
line = vfp.FieldLine( field, [x, y], start_v=[0, -1],directions='forward' ) |
37 |
|
|
# draw the lin on the document |
38 |
|
|
doc.draw_line(line,arrows_style={'min_arrows':1,'scale':0.4,'max_arrows':3}) |
39 |
|
|
|
40 |
|
|
#right left |
41 |
|
|
for i in range(N): |
42 |
|
|
x = 4 |
43 |
|
|
y = -3 + 6 * float(i) / float(N) |
44 |
|
|
# generate the line |
45 |
|
|
# this takes the initial position, the x and y components of the initial direction, and whether or not should go forward |
46 |
|
|
# or backward. |
47 |
|
|
line = vfp.FieldLine( field, [x, y], start_v=[-1, 0],directions='forward' ) |
48 |
|
|
# draw the lin on the document |
49 |
|
|
doc.draw_line(line,arrows_style={'min_arrows':1,'scale':0.4,'max_arrows':3}) |
50 |
|
|
|
51 |
|
|
#left right |
52 |
|
|
for i in range(N): |
53 |
|
|
x = -4 |
54 |
|
|
y = -3 + 6 * float(i) / float(N) |
55 |
|
|
# generate the line |
56 |
|
|
# this takes the initial position, the x and y components of the initial direction, and whether or not should go forward |
57 |
|
|
# or backward. |
58 |
|
|
line = vfp.FieldLine( field, [x, y], start_v=[1, 0],directions='forward' ) |
59 |
|
|
# draw the lin on the document |
60 |
|
|
doc.draw_line(line,arrows_style={'min_arrows':1,'scale':0.4,'max_arrows':3}) |
61 |
|
|
doc.write() |
62 |
|
|
|