def wirecube(s): c = curve(color=(1, 1, 1), radius=1) pts = [(-s, -s, -s), (-s, -s, s), (-s, s, s), (-s, s, -s), (-s, -s, -s), (s, -s, -s), (s, s, -s), (-s, s, -s), (s, s, -s), (s, s, s), (-s, s, s), (s, s, s), (s, -s, s), (-s, -s, s), (s, -s, s), (s, -s, -s)] for pt in pts: c.append(pt)
def wirecube(s): c = curve(color = (1,1,1), radius=1) pts = [(-s, -s, -s),(-s, -s, s), (-s, s, s), (-s, s, -s), (-s, -s, -s), (s, -s, -s), (s, s, -s), (-s, s, -s), (s, s, -s), (s, s, s), (-s, s, s), (s, s, s), (s, -s, s), (-s, -s, s), (s, -s, s),(s, -s, -s)] for pt in pts: c.append(pt)
#!/usr/bin/env python # Author: Raashid Baig <*****@*****.**> # License: BSD Style. from enthought.tvtk.tools.visual import curve, box, vector, show from numpy import arange, array lorenz = curve(color=(1, 1, 1), radius=0.3) # Draw grid for x in xrange(0, 51, 10): curve(points=[[x, 0, -25], [x, 0, 25]], color=(0, 0.5, 0), radius=0.3) box(pos=(x, 0, 0), axis=(0, 0, 50), height=0.4, width=0.4, length=50) for z in xrange(-25, 26, 10): curve(points=[[0, 0, z], [50, 0, z]], color=(0, 0.5, 0), radius=0.3) box(pos=(25, 0, z), axis=(50, 0, 0), height=0.4, width=0.4, length=50) dt = 0.01 y = vector(35.0, -10.0, -7.0) pts = [] for i in xrange(2000): # Integrate a funny differential equation dydt = vector(-8.0 / 3 * y[0] + y[1] * y[2], -10 * y[1] + 10 * y[2], -y[1] * y[0] + 28 * y[1] - y[2]) y = y + dydt * dt pts.append(y) if len(pts) > 20:
box (pos = (xx,yy,zz), length=x, height=y, width=z, color=(red,green,blue)) def wirecube(s): c = curve(color = (1,1,1), radius=1) pts = [(-s, -s, -s),(-s, -s, s), (-s, s, s), (-s, s, -s), (-s, -s, -s), (s, -s, -s), (s, s, -s), (-s, s, -s), (s, s, -s), (s, s, s), (-s, s, s), (s, s, s), (s, -s, s), (-s, -s, s), (s, -s, s),(s, -s, -s)] for pt in pts: c.append(pt) side = 150.0 cube = box(size = (side,side,side), representation = 'w' ) i = 0 while i < 100: random_box() i = i + 1 arrow(axis=(0,12,0), radius_shaft=3.5, color = (1,0,0)) ball = sphere(pos=(-side/2.,-side/2.,-side/2.),color=(1,1,0),radius=3) disk = cylinder(pos=(side/2.,side/2.,-side/2.),color=(.3,.3,1),axis=(1,1,0),radius=5) xx = arange(0,4*pi,pi/10.) spring=curve(color=(1,.7,.1), radius=0.4) for y in xx: spring.append([20+cos(2*y), y/2.-30, -20+sin(2*y)+30]) show()
giant = sphere(pos=(-1.0e11, 0, 0), radius=2e10, color=(1, 0, 0), mass=2e30) dwarf = sphere(pos=(1.5e11, 0, 0), radius=1e10, color=(1, 1, 0), mass=1e30) giant.p = vector(0, 0, -1e4) * giant.mass dwarf.p = -1*giant.p # creating the curve which will trace the paths of actors for a in [giant, dwarf]: a.orbit = curve(radius=2e9, color=a.color) dt = 86400 def anim(): #Creating the animation function which will be called at #uniform timeperiod through the iterate function dist = dwarf.pos - giant.pos force = 6.7e-11 * giant.mass * dwarf.mass * \ dist/(sqrt(dist[0]**2 + dist[1]**2 + dist[2]**2))**3 giant.p = giant.p + force*dt dwarf.p = dwarf.p - force*dt for a in [giant, dwarf]: a.pos = a.pos + (a.p/a.mass)*dt a.orbit.append(a.pos)
from math import sqrt from enthought.tvtk.tools.visual import sphere, iterate, show, vector, curve #Creating the actors for the scene giant = sphere(pos=(-1.0e11, 0, 0), radius=2e10, color=(1, 0, 0), mass=2e30) dwarf = sphere(pos=(1.5e11, 0, 0), radius=1e10, color=(1, 1, 0), mass=1e30) giant.p = vector(0, 0, -1e4) * giant.mass dwarf.p = -1 * giant.p # creating the curve which will trace the paths of actors for a in [giant, dwarf]: a.orbit = curve(radius=2e9, color=a.color) dt = 86400 def anim(): #Creating the animation function which will be called at #uniform timeperiod through the iterate function dist = dwarf.pos - giant.pos force = 6.7e-11 * giant.mass * dwarf.mass * \ dist/(sqrt(dist[0]**2 + dist[1]**2 + dist[2]**2))**3 giant.p = giant.p + force * dt dwarf.p = dwarf.p - force * dt for a in [giant, dwarf]: a.pos = a.pos + (a.p / a.mass) * dt
pts = [(-s, -s, -s), (-s, -s, s), (-s, s, s), (-s, s, -s), (-s, -s, -s), (s, -s, -s), (s, s, -s), (-s, s, -s), (s, s, -s), (s, s, s), (-s, s, s), (s, s, s), (s, -s, s), (-s, -s, s), (s, -s, s), (s, -s, -s)] for pt in pts: c.append(pt) side = 150.0 cube = box(size=(side, side, side), representation='w') i = 0 while i < 100: random_box() i = i + 1 arrow(axis=(0, 12, 0), radius_shaft=3.5, color=(1, 0, 0)) ball = sphere(pos=(-side / 2., -side / 2., -side / 2.), color=(1, 1, 0), radius=3) disk = cylinder(pos=(side / 2., side / 2., -side / 2.), color=(.3, .3, 1), axis=(1, 1, 0), radius=5) xx = arange(0, 4 * pi, pi / 10.) spring = curve(color=(1, .7, .1), radius=0.4) for y in xx: spring.append([20 + cos(2 * y), y / 2. - 30, -20 + sin(2 * y) + 30]) show()
#!/usr/bin/env python # Author: Raashid Baig <*****@*****.**> # License: BSD Style. from enthought.tvtk.tools.visual import curve, box, vector, show from numpy import arange, array lorenz = curve( color = (1,1,1), radius=0.3 ) # Draw grid for x in xrange(0,51,10): curve(points = [[x,0,-25],[x,0,25]], color = (0,0.5,0), radius = 0.3 ) box(pos=(x,0,0), axis=(0,0,50), height=0.4, width=0.4, length = 50) for z in xrange(-25,26,10): curve(points = [[0,0,z], [50,0,z]] , color = (0,0.5,0), radius = 0.3 ) box(pos=(25,0,z), axis=(50,0,0), height=0.4, width=0.4, length = 50) dt = 0.01 y = vector(35.0, -10.0, -7.0) pts = [] for i in xrange(2000): # Integrate a funny differential equation dydt = vector( -8.0/3*y[0] + y[1]*y[2], - 10*y[1] + 10*y[2], - y[1]*y[0] + 28*y[1] - y[2]) y = y + dydt * dt pts.append(y)
color=pedestal.color) shaft = cylinder(axis=(Lshaft, 0, 0), length=Lshaft, radius=Rshaft, color=(0, 1, 0)) rotor = cylinder(pos=(Lshaft / 2 - Drotor / 2, 0, 0), axis=(Drotor, 0, 0), length=Drotor, radius=Rrotor, color=(1, 0, 0)) gyro = frame(shaft, rotor) gyro.axis = (sin(theta) * sin(phi), cos(theta), sin(theta) * cos(phi)) trail = curve(radius=Rshaft / 8., color=(1, 1, 0)) r = Lshaft / 2. dt = 0.0001 t = 0. Nsteps = 20 # number of calculational steps between graphics updates def anim(): global theta, phidot, alphadot, M, g, r, thetadot, phi, alpha, t for step in range(Nsteps): # multiple calculation steps for accuracy # Calculate accelerations of the Lagrangian coordinates: atheta = (phidot**2 * sin(theta) * cos(theta) - 2. * (alphadot + phidot * cos(theta)) * phidot * sin(theta) + 2. * M * g * r * sin(theta) / I) aphi = 2. * thetadot * (alphadot - phidot * cos(theta)) / sin(theta)
height=hpedestal, length=wpedestal, width=wpedestal, color=(0.4,0.4,0.5)) base = box(pos=top-vector(0,hpedestal+tbase/2.,0), height=tbase, length=wbase, width=wbase, color=pedestal.color) shaft = cylinder(axis=(Lshaft,0,0), length = Lshaft, radius=Rshaft, color=(0,1,0)) rotor = cylinder(pos=(Lshaft/2 - Drotor/2, 0, 0), axis=(Drotor, 0, 0), length = Drotor, radius=Rrotor, color=(1,0,0)) gyro = frame(shaft, rotor) gyro.axis = (sin(theta)*sin(phi),cos(theta),sin(theta)*cos(phi)) trail = curve(radius=Rshaft/8., color=(1,1,0)) r = Lshaft/2. dt = 0.0001 t = 0. Nsteps = 20 # number of calculational steps between graphics updates def anim(): global theta, phidot, alphadot, M, g, r, thetadot, phi, alpha, t for step in range(Nsteps): # multiple calculation steps for accuracy # Calculate accelerations of the Lagrangian coordinates: atheta = (phidot**2*sin(theta)*cos(theta) -2.*(alphadot+phidot*cos(theta))*phidot*sin(theta) +2.*M*g*r*sin(theta)/I) aphi = 2.*thetadot*(alphadot-phidot*cos(theta))/sin(theta) aalpha = phidot*thetadot*sin(theta)-aphi*cos(theta)
pprecess = -pprecess support = Box(pos = top+MVector(0,0.01,0), size = (0.2,0.02,0.2), color = (0,1,0)) spring = Helix(pos = top, axis = vector(-0.161579, -0.98686, 0), radius = Rspring, color = (1,0.7,0.2)) gyro1 = Frame(pos = top+spring.axis) # gyro.pos at end of spring gyro1.axis = MVector(1,0,0) shaft = Cylinder(pos = gyro1.pos, axis = Lshaft*gyro1.axis, radius = Rshaft, color = (0.85,0.85,0.85), length = 1.0) rotor = Cylinder(pos = 0.5*gyro1.axis*(Lshaft-Drotor), axis = gyro1.axis*Drotor, radius = Rrotor, color = (0.5,0.5,0.5), length = 0.1) stripe1 = curve(color = color.green, points = [rotor.pos+1.03*rotor.axis+vector(0,Rrotor,0), rotor.pos+1.03*rotor.axis-vector(0,Rrotor,0)]) stripe2 = curve(color = color.green, points = [rotor.pos-0.03*rotor.axis+vector(0,Rrotor,0), rotor.pos-0.03*rotor.axis-vector(0,Rrotor,0)]) gyro = Frame(stripe1, stripe2) # gyro.pos at end of spring gyro.pos = top+spring.axis # gyro.pos at end of spring gyro.axis = vector(1,0,0) gyro.rotate(axis=(0,1,0), angle = 180.0, origin = gyro.pos) cm = gyro.pos+0.5*Lshaft*gyro.axis # center of mass of shaft Lrot = I*omega*gyro.axis p = pprecess dt = 0.01
shaft = Cylinder(pos=gyro1.pos, axis=Lshaft * gyro1.axis, radius=Rshaft, color=(0.85, 0.85, 0.85), length=1.0) rotor = Cylinder(pos=0.5 * gyro1.axis * (Lshaft - Drotor), axis=gyro1.axis * Drotor, radius=Rrotor, color=(0.5, 0.5, 0.5), length=0.1) stripe1 = curve(color=color.green, points=[ rotor.pos + 1.03 * rotor.axis + vector(0, Rrotor, 0), rotor.pos + 1.03 * rotor.axis - vector(0, Rrotor, 0) ]) stripe2 = curve(color=color.green, points=[ rotor.pos - 0.03 * rotor.axis + vector(0, Rrotor, 0), rotor.pos - 0.03 * rotor.axis - vector(0, Rrotor, 0) ]) gyro = Frame(stripe1, stripe2) # gyro.pos at end of spring gyro.pos = top + spring.axis # gyro.pos at end of spring gyro.axis = vector(1, 0, 0) gyro.rotate(axis=(0, 1, 0), angle=180.0, origin=gyro.pos) cm = gyro.pos + 0.5 * Lshaft * gyro.axis # center of mass of shaft
#Longitud pendulo 2 l2 = 2.0 #Longitud pendulo 3 l3 = 3.0 #Longitud pendulo 4 l4 = 2.0 #Radio de cada esfera radio = 0.2 #Creando pendulo 1 pendulo1 = visual.sphere( radius=radio, \ color=(0.0, 0.0, 1.0) ) pendulo1.pos = [1, -l1, 0] pendulo1.t = 0 pendulo1.dt = 1 cuerda1 = visual.curve( points=[(1,0,0), (1,-l1,0)], \ radius=0.02 ) #Creando pendulo 2 pendulo2 = visual.sphere( radius=radio, \ color=(0.0, 0.0, 1.0) ) pendulo2.pos = [2, -l2, 0] pendulo2.t = 0 pendulo2.dt = 1 cuerda2 = visual.curve( points=[(2,0,0), (2,-l2,0)], \ radius=0.02 ) #Creando pendulo 3 pendulo3 = visual.sphere( radius=radio, \ color=(0.0, 0.0, 1.0) ) pendulo3.pos = [3, -l3, 0] pendulo3.t = 0
#Longitud pendulo 2 l2 = 2.0 #Longitud pendulo 3 l3 = 3.0 #Longitud pendulo 4 l4 = 2.0 #Radio de cada esfera radio = 0.2 #Creando pendulo 1 pendulo1 = visual.sphere( radius=radio, \ color=(0.0, 0.0, 1.0) ) pendulo1.pos = [ 1, -l1, 0 ] pendulo1.t = 0 pendulo1.dt = 1 cuerda1 = visual.curve( points=[(1,0,0), (1,-l1,0)], \ radius=0.02 ) #Creando pendulo 2 pendulo2 = visual.sphere( radius=radio, \ color=(0.0, 0.0, 1.0) ) pendulo2.pos = [ 2, -l2, 0 ] pendulo2.t = 0 pendulo2.dt = 1 cuerda2 = visual.curve( points=[(2,0,0), (2,-l2,0)], \ radius=0.02 ) #Creando pendulo 3 pendulo3 = visual.sphere( radius=radio, \ color=(0.0, 0.0, 1.0) ) pendulo3.pos = [ 3, -l3, 0 ] pendulo3.t = 0