| 1 |
#!/opt/local/bin/python2.7 |
| 2 |
|
| 3 |
'''An example script that generates a picture of the field lines for an electric dipole.''' |
| 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( 'Dipole', width=800,height=600,unit=100) |
| 10 |
|
| 11 |
# create a field opbject |
| 12 |
field = vfp.Field() |
| 13 |
# add the dipole |
| 14 |
# note, parameters are should be [ r_x, r_y, p_x, p_y], where r is the |
| 15 |
# position vector, p is the dipole vector |
| 16 |
field.add_element('dipoles' , [ [ 0, 0, -1, 0] ] ) |
| 17 |
|
| 18 |
# draw the charges for the field on the document |
| 19 |
doc.draw_charges(field) |
| 20 |
|
| 21 |
# start drawing the field lines we are going to draw 20 field lines |
| 22 |
# comming off of the dipole at uniformly spaced angles. |
| 23 |
N = 37 |
| 24 |
for i in range(N): |
| 25 |
# compute the angle that the line will start off at |
| 26 |
angle = float(i) * 2.0* math.pi / float(N-1) |
| 27 |
direction = 'forward' |
| 28 |
|
| 29 |
if (math.fabs(angle - math.pi) < 1.0e-3): |
| 30 |
direction = 'backwards' |
| 31 |
|
| 32 |
print angle, direction |
| 33 |
# generate the line this takes the initial position, the x and y |
| 34 |
# components of the initial direction, and whether or not should |
| 35 |
# go forward or backward. |
| 36 |
line = vfp.FieldLine( field, [0.05*math.cos(angle),0.05*math.sin(angle)], start_v=[math.cos( angle ) , math.sin( angle )],directions=direction ) |
| 37 |
# draw the lin on the document |
| 38 |
doc.draw_line(line,arrows_style={'min_arrows':1,'scale':0.5,'max_arrows':2}) |
| 39 |
|
| 40 |
# write the document |
| 41 |
doc.write() |
| 42 |
|