| 1 |
gezelter |
4411 |
#!/opt/local/bin/python2.7 |
| 2 |
|
|
|
| 3 |
|
|
'''An example script that generates a picture of the field lines for an electric field.''' |
| 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( 'UniformField', width=800,height=600,unit=100) |
| 10 |
|
|
|
| 11 |
|
|
# create a field opbject |
| 12 |
|
|
field = vfp.Field() |
| 13 |
|
|
# note, parameters are should be [ Ex, Ey ] |
| 14 |
|
|
field.add_element('homogeneous' , [ [ 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 |
|
|
doc.write() |
| 30 |
|
|
|