| 1 |
|
| 2 |
|
| 3 |
"""A simple example demonstrating the creation of actors and animating |
| 4 |
the in a scene using visual modeule.""" |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
from tvtk.tools.visual import box, vector, frame, iterate, show |
| 16 |
from math import pi, sin |
| 17 |
|
| 18 |
g = 9.8 |
| 19 |
M1 = 2.0 |
| 20 |
M2 = 1.0 |
| 21 |
d = 0.05 |
| 22 |
gap = 2.*d |
| 23 |
L1 = 0.5 |
| 24 |
L1display = L1+d |
| 25 |
L2 = 1.0 |
| 26 |
L2display = L2+d/2. |
| 27 |
|
| 28 |
A = (1./4.)*M1*L1**2+(1./12.)*M1*L1**2+M2*L1**2 |
| 29 |
B = (1./2.)*M2*L1*L2 |
| 30 |
C = g*L1*(M1/2.+M2) |
| 31 |
D = M2*L1*L2/2. |
| 32 |
E = (1./12.)*M2*L2**2+(1./4.)*M2*L2**2 |
| 33 |
F = g*L2*M2/2. |
| 34 |
|
| 35 |
hpedestal = 1.3*(L1+L2) |
| 36 |
wpedestal = 0.1 |
| 37 |
tbase = 0.05 |
| 38 |
wbase = 8.*gap |
| 39 |
offset = 2.*gap |
| 40 |
top = vector(0,0,0) |
| 41 |
|
| 42 |
theta1 = 1.3*pi/2. |
| 43 |
theta1dot = 0 |
| 44 |
theta2 = 0 |
| 45 |
theta2dot = 0 |
| 46 |
|
| 47 |
pedestal = box(pos = (top - vector(0, hpedestal/2.0, offset)),size = (wpedestal, 1.1*hpedestal, wpedestal), color = (0.4,0.4,0.5)) |
| 48 |
|
| 49 |
base = box(pos = (top - vector(0,hpedestal + tbase/2.0, offset)),size=(wbase, tbase, wbase),color = (0.4,0.4,0.5)) |
| 50 |
|
| 51 |
bar1 = box(pos=(L1display/2.0 - d/2.0, 0, -(gap+d)/2.0), size=(L1display, d, d), color=(1,0,0)) |
| 52 |
bar1b = box(pos=(L1display/2.0 - d/2.0, 0, (gap+d)/2.0), size=(L1display, d, d), color=(1,0,0)) |
| 53 |
|
| 54 |
frame1 = frame(bar1, bar1b) |
| 55 |
frame1.pos = (0.0, 0.0, 0.0) |
| 56 |
frame1.axis = (0.0, -1.0, 0.0) |
| 57 |
frame1.rotate(axis=(0,0,1), angle = 180.0*theta1/pi) |
| 58 |
|
| 59 |
bar2 = box(pos = (L2display/2.0 - d/2.0, 0, 0), size = (L2display, d, d), color = (0,1,0)) |
| 60 |
|
| 61 |
frame2 = frame(bar2) |
| 62 |
frame2.pos = (0.0, -1.0*L1, 0.0) |
| 63 |
frame2.axis = (0.0, -1.0, 0.0) |
| 64 |
frame2.rotate(axis = (0,0,1), angle = 180.0*theta2/pi) |
| 65 |
|
| 66 |
dt = 0.001 |
| 67 |
|
| 68 |
def anim(): |
| 69 |
global theta1, theta2, theta1dot, theta2dot |
| 70 |
atheta1 = ((E*C/B)*sin(theta1)-F*sin(theta2))/(D-E*A/B) |
| 71 |
atheta2 = -(A*atheta1+C*sin(theta1))/B |
| 72 |
|
| 73 |
theta1dot = theta1dot + atheta1*dt |
| 74 |
theta2dot = theta2dot + atheta2*dt |
| 75 |
|
| 76 |
dtheta1 = theta1dot*dt |
| 77 |
dtheta2 = theta2dot*dt |
| 78 |
theta1 = theta1 + dtheta1 |
| 79 |
theta2 = theta2 + dtheta2 |
| 80 |
|
| 81 |
frame1.rotate(axis = (0,0,1), angle = 180.0*dtheta1/pi) |
| 82 |
|
| 83 |
frame2.pos = top + frame1.axis*L1 |
| 84 |
frame2.rotate(axis = (0,0,1), angle = 180*dtheta2/pi) |
| 85 |
|
| 86 |
a = iterate(20, anim) |
| 87 |
a.edit_traits() |
| 88 |
show() |