| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
from math import sin, pi |
| 7 |
|
| 8 |
from numpy import zeros, arange |
| 9 |
|
| 10 |
from tvtk.tools.visual import show, Curve, iterate, MVector |
| 11 |
|
| 12 |
|
| 13 |
def main(): |
| 14 |
dt = 0.1 |
| 15 |
|
| 16 |
x = arange(-50,50) |
| 17 |
wpoints1 = zeros((100,3), float) |
| 18 |
wpoints2 = zeros((100,3), float) |
| 19 |
wpoints3 = zeros((100,3), float) |
| 20 |
wpoints4 = zeros((100,3), float) |
| 21 |
|
| 22 |
for i in range (0,100,1): |
| 23 |
wpoints1[i] = [x[i], -30, 0] |
| 24 |
wpoints2[i] = [x[i], -15, 0] |
| 25 |
wpoints3[i] = [x[i], 0, 0] |
| 26 |
wpoints4[i] = [x[i], 15, 0] |
| 27 |
|
| 28 |
band1 = Curve(points = wpoints1, k = 6.0, color = (1,0,0), |
| 29 |
mass = 2.0, radius = 0.5, momentum = zeros((100, 3), float)) |
| 30 |
|
| 31 |
band2 = Curve(points = wpoints2, k = 6.0, color = (1,1,0), |
| 32 |
mass = 2.0, radius = 0.5, momentum = zeros((100, 3), float)) |
| 33 |
|
| 34 |
band3 = Curve(points = wpoints3, k = 6.0, color = (0,1,0), |
| 35 |
mass = 2.0, radius = 0.5, momentum = zeros((100, 3), float)) |
| 36 |
|
| 37 |
band4 = Curve(points = wpoints4, k = 6.0, color = (0,0,1), |
| 38 |
mass = 2.0, radius = 0.5, momentum = zeros((100, 3), float)) |
| 39 |
|
| 40 |
for i in range(0,25,1): |
| 41 |
band1.momentum[i,1] = sin(x[i]*pi/25.0)*3 |
| 42 |
|
| 43 |
for i in range(0,25,1): |
| 44 |
band2.momentum[i,1] = sin(x[i]*2*pi/25.0)*5 |
| 45 |
|
| 46 |
for i in range(0,25,1): |
| 47 |
band3.momentum[i,0] = sin(x[i]*pi/25.0)*5 |
| 48 |
|
| 49 |
for i in range(0,100,1): |
| 50 |
band4.momentum[i,1] = sin(x[i]*4*pi/100.0)*2 |
| 51 |
|
| 52 |
def anim(): |
| 53 |
band1.momentum[0] = band1.momentum[-1] = MVector(0,0,0) |
| 54 |
band2.momentum[0] = band2.momentum[-1] = MVector(0,0,0) |
| 55 |
band3.momentum[0] = band3.momentum[-1] = MVector(0,0,0) |
| 56 |
band4.momentum[0] = band4.momentum[-1] = MVector(0,0,0) |
| 57 |
|
| 58 |
band1.points = band1.points + (band1.momentum/band1.mass*dt) |
| 59 |
band2.points = band2.points + (band2.momentum/band2.mass*dt) |
| 60 |
band3.points = band3.points + (band3.momentum/band3.mass*dt) |
| 61 |
band4.points = band4.points + (band4.momentum/band4.mass*dt) |
| 62 |
|
| 63 |
force1 = band1.k * (band1.points[1:] - band1.points[:-1]) |
| 64 |
force2 = band2.k * (band2.points[1:] - band2.points[:-1]) |
| 65 |
force3 = band3.k * (band3.points[1:] - band3.points[:-1]) |
| 66 |
force4 = band4.k * (band4.points[1:] - band4.points[:-1]) |
| 67 |
|
| 68 |
band1.momentum[:-1] = band1.momentum[:-1] + force1 * dt |
| 69 |
band2.momentum[:-1] = band2.momentum[:-1] + force2 * dt |
| 70 |
band3.momentum[:-1] = band3.momentum[:-1] + force3 * dt |
| 71 |
band4.momentum[:-1] = band4.momentum[:-1] + force4 * dt |
| 72 |
|
| 73 |
band1.momentum[1:] = band1.momentum[1:] - force1 * dt |
| 74 |
band2.momentum[1:] = band2.momentum[1:] - force2 * dt |
| 75 |
band3.momentum[1:] = band3.momentum[1:] - force3 * dt |
| 76 |
band4.momentum[1:] = band4.momentum[1:] - force4 * dt |
| 77 |
|
| 78 |
a = iterate(20, anim) |
| 79 |
show() |
| 80 |
return a |
| 81 |
|
| 82 |
if __name__ == '__main__': |
| 83 |
main() |