def anim(): 
    #Evolucion del pendulo 1
    pendulo1.t = pendulo1.t + pendulo1.dt
    i = pendulo1.t
    pendulo1.pos = visual.vector( 1, \
    -l1*np.cos(theta1_t[i]), l1*np.sin(theta1_t[i]) )
    delta_thetha1 = theta1_t[i-1] - theta1_t[i]
    cuerda1.rotate( 180*delta_thetha1/np.pi, [1.,0.,0] )
    
    #Evolucion del pendulo 2
    pendulo2.t = pendulo2.t + pendulo2.dt
    i = pendulo2.t
    pendulo2.pos = visual.vector( 2, \
    -l2*np.cos(theta2_t[i]), l2*np.sin(theta2_t[i]) )
    delta_thetha2 = theta2_t[i-1] - theta2_t[i]
    cuerda2.rotate( 180*delta_thetha2/np.pi, [1.,0.,0] )
    
    #Evolucion del pendulo 3
    pendulo3.t = pendulo3.t + pendulo3.dt
    i = pendulo3.t
    pendulo3.pos = visual.vector( 3, \
    -l3*np.cos(theta3_t[i]), l3*np.sin(theta3_t[i]) )
    delta_thetha3 = theta3_t[i-1] - theta3_t[i]
    cuerda3.rotate( 180*delta_thetha3/np.pi, [1.,0.,0] )
    
    #Evolucion del pendulo 4
    pendulo4.t = pendulo4.t + pendulo4.dt
    i = pendulo4.t
    pendulo4.pos = visual.vector( 4, \
    -l4*np.cos(theta4_t[i]), l4*np.sin(theta4_t[i]) )
    delta_thetha4 = theta4_t[i-1] - theta4_t[i]
    cuerda4.rotate( 180*delta_thetha4/np.pi, [1.,0.,0] )
Exemple #2
0
def anim():
    #Evolucion del pendulo 1
    pendulo1.t = pendulo1.t + pendulo1.dt
    i = pendulo1.t
    pendulo1.pos = visual.vector( 1, \
    -l1*np.cos(theta1_t[i]), l1*np.sin(theta1_t[i]) )
    delta_thetha1 = theta1_t[i - 1] - theta1_t[i]
    cuerda1.rotate(180 * delta_thetha1 / np.pi, [1., 0., 0])

    #Evolucion del pendulo 2
    pendulo2.t = pendulo2.t + pendulo2.dt
    i = pendulo2.t
    pendulo2.pos = visual.vector( 2, \
    -l2*np.cos(theta2_t[i]), l2*np.sin(theta2_t[i]) )
    delta_thetha2 = theta2_t[i - 1] - theta2_t[i]
    cuerda2.rotate(180 * delta_thetha2 / np.pi, [1., 0., 0])

    #Evolucion del pendulo 3
    pendulo3.t = pendulo3.t + pendulo3.dt
    i = pendulo3.t
    pendulo3.pos = visual.vector( 3, \
    -l3*np.cos(theta3_t[i]), l3*np.sin(theta3_t[i]) )
    delta_thetha3 = theta3_t[i - 1] - theta3_t[i]
    cuerda3.rotate(180 * delta_thetha3 / np.pi, [1., 0., 0])

    #Evolucion del pendulo 4
    pendulo4.t = pendulo4.t + pendulo4.dt
    i = pendulo4.t
    pendulo4.pos = visual.vector( 4, \
    -l4*np.cos(theta4_t[i]), l4*np.sin(theta4_t[i]) )
    delta_thetha4 = theta4_t[i - 1] - theta4_t[i]
    cuerda4.rotate(180 * delta_thetha4 / np.pi, [1., 0., 0])
def anim():
    #Evolucion de la bola 1
    bola1.t = bola1.t + bola1.dt
    i = bola1.t
    bola1.pos = visual.vector(x1_t[i], y1_t[i], r1)

    #Evolucion de la bola 2
    bola2.t = bola2.t + bola2.dt
    i = bola2.t
    bola2.pos = visual.vector(x2_t[i], y2_t[i], r2)

    #Evolucion de la bola 3
    bola3.t = bola3.t + bola3.dt
    i = bola3.t
    bola3.pos = visual.vector(x3_t[i], y3_t[i], r3)
def anim(): 
    #Evolucion de la bola 1
    bola1.t = bola1.t + bola1.dt
    i = bola1.t
    bola1.pos = visual.vector( x1_t[i], y1_t[i], r1 )
    
    #Evolucion de la bola 2
    bola2.t = bola2.t + bola2.dt
    i = bola2.t
    bola2.pos = visual.vector( x2_t[i], y2_t[i], r2 )
    
    #Evolucion de la bola 3
    bola3.t = bola3.t + bola3.dt
    i = bola3.t
    bola3.pos = visual.vector( x3_t[i], y3_t[i], r3 )
Exemple #5
0
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)
        # Update velocities of the Lagrangian coordinates:
        thetadot = thetadot + atheta * dt
        phidot = phidot + aphi * dt
        alphadot = alphadot + aalpha * dt
        # Update Lagrangian coordinates:
        theta = theta + thetadot * dt
        phi = phi + phidot * dt
        alpha = alpha + alphadot * dt

    gyro.axis = vector(
        sin(theta) * sin(phi), cos(theta),
        sin(theta) * cos(phi))
    # Display approximate rotation of rotor and shaft:
    gyro.rotate(axis=gyro.axis, angle=alphadot * dt * Nsteps, origin=gyro.pos)
    trail.append(gyro.pos + gyro.axis * Lshaft)
    t = t + dt * Nsteps
Exemple #6
0
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)
        # Update velocities of the Lagrangian coordinates:
        thetadot = thetadot+atheta*dt
        phidot = phidot+aphi*dt
        alphadot = alphadot+aalpha*dt
        # Update Lagrangian coordinates:
        theta = theta+thetadot*dt
        phi = phi+phidot*dt
        alpha = alpha+alphadot*dt

    gyro.axis = vector(sin(theta)*sin(phi),cos(theta),sin(theta)*cos(phi))
    # Display approximate rotation of rotor and shaft:
    gyro.rotate(axis = gyro.axis, angle=alphadot*dt*Nsteps, origin = gyro.pos)
    trail.append(gyro.pos + gyro.axis * Lshaft)
    t = t+dt*Nsteps
Exemple #7
0
def main():
    # Creating parameters for box size
    side = 4.0
    thk = 0.3
    s2 = 2 * side - thk
    s3 = 2 * side + thk
    # Creating the 6 walls
    wallR = box(pos=(side, 0, 0), size=(thk, s3, s2), color=(1, 0, 0))
    wallL = box(pos=(-side, 0, 0), size=(thk, s3, s2), color=(1, 0, 0))
    wallB = box(pos=(0, -side, 0), size=(s3, thk, s3), color=(0, 0, 1))
    wallT = box(pos=(0, side, 0), size=(s3, thk, s3), color=(0, 0, 1))
    wallBK = box(pos=(0, 0, -side), size=(s2, s2, thk), color=(0.7, 0.7, 0.7))
    # Creating the ball
    ball = sphere(radius=0.4, color=(0, 1, 0))
    ball.vector = vector(-0.15, -0.23, 0.27)

    side = side - thk * 0.5 - ball.radius

    ball.t = 0.0
    ball.dt = 0.5

    def anim():
        #Creating the animation function which will be called at
        #uniform timeperiod through the iterate function
        ball.t = ball.t + ball.dt
        ball.pos = ball.pos + ball.vector * ball.dt
        if not (side > ball.x > -side):
            ball.vector.x = -ball.vector.x
        if not (side > ball.y > -side):
            ball.vector.y = -ball.vector.y
        if not (side > ball.z > -side):
            ball.vector.z = -ball.vector.z

    a = iterate(20, anim)
    show()
    return a
Exemple #8
0
def main():
    # Creating parameters for box size
    side = 4.0
    thk = 0.3
    s2 = 2 * side - thk
    s3 = 2 * side + thk
    # Creating the 6 walls
    wallR = box(pos=(side, 0, 0), size=(thk, s3, s2), color=(1, 0, 0))
    wallL = box(pos=(-side, 0, 0), size=(thk, s3, s2), color=(1, 0, 0))
    wallB = box(pos=(0, -side, 0), size=(s3, thk, s3), color=(0, 0, 1))
    wallT = box(pos=(0, side, 0), size=(s3, thk, s3), color=(0, 0, 1))
    wallBK = box(pos=(0, 0, -side), size=(s2, s2, thk), color=(0.7, 0.7, 0.7))
    # Creating the ball
    ball = sphere(radius=0.4, color=(0, 1, 0))
    ball.vector = vector(-0.15, -0.23, 0.27)

    side = side - thk * 0.5 - ball.radius

    ball.t = 0.0
    ball.dt = 0.5

    def anim():
        # Creating the animation function which will be called at
        # uniform timeperiod through the iterate function
        ball.t = ball.t + ball.dt
        ball.pos = ball.pos + ball.vector * ball.dt
        if not (side > ball.x > -side):
            ball.vector.x = -ball.vector.x
        if not (side > ball.y > -side):
            ball.vector.y = -ball.vector.y
        if not (side > ball.z > -side):
            ball.vector.z = -ball.vector.z

    a = iterate(20, anim)
    show()
    return a
Exemple #9
0
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
Exemple #10
0
#!/usr/bin/env python
"""A simple example demonstrating the creation of actors and animating
the in a scene using visual modeule."""
# Author: Raashid Baig <*****@*****.**>
# License: BSD Style.

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
Exemple #11
0
    "Return the magnitude of a vector"
    return math.sqrt((v*v).sum())

# Geometric parameters  (all in MKS units)
theta = math.pi/4  # initial angle of gun
D = 20  # width ...
H = 20  # height of floor
g = -9.8  # gravity
gun_len = 2  # size of gun
arrow_len = 4  # and of arrow
v0_default = 15  # default for initial velocity if not given

# Numerical simulation parameters
dt = 0.01
# Update for all velocities under constant acceleration (gravity)
dv = V.vector(0,g*dt,0)

# Tolerance for deciding whether a collision happened
impact_distance = 0.5

# Initialize arguments
try:
    v0 = float(sys.argv[1])
except:
    v0 = v0_default
    print 'Using default v0 =',v0,'m/s.'

# Build 3d world

# Define the line of sight
sight = V.vector(math.cos(theta),math.sin(theta),0)
Exemple #12
0
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:
        lorenz.extend(pts)
        pts[:] = []

show()
Exemple #13
0
# The Lagrangian variables are polar angle theta,
# azimuthal angle phi, and spin angle alpha.

Lshaft = 1. # length of gyroscope shaft
Rshaft = 0.03 # radius of gyroscope shaft
M = 1. # mass of gyroscope (massless shaft)
Rrotor = 0.4 # radius of gyroscope rotor
Drotor = 0.1 # thickness of gyroscope rotor
Dsquare = 1.4*Drotor # thickness of square that turns with rotor
I = 0.5*M*Rrotor**2. # moment of inertia of gyroscope
hpedestal = Lshaft # height of pedestal
wpedestal = 0.1 # width of pedestal
tbase = 0.05 # thickness of base
wbase = 3.*wpedestal # width of base
g = 9.8
Fgrav = vector(0,-M*g,0)
top = vector(0,0,0) # top of pedestal

theta = pi/3. # initial polar angle of shaft (from vertical)
thetadot = 0 # initial rate of change of polar angle
alpha = 0 # initial spin angle
alphadot = 15 # initial rate of change of spin angle (spin ang. velocity)
phi = -pi/2. # initial azimuthal angle
phidot = 0 # initial rate of change of azimuthal angle
# Comment in following line to get pure precession
##phidot = (-alphadot+sqrt(alphadot**2+2*M*g*r*cos(theta)/I))/cos(theta)

pedestal = box(pos=top-vector(0,hpedestal/2.,0),
                 height=hpedestal, length=wpedestal, width=wpedestal,
                 color=(0.4,0.4,0.5))
base = box(pos=top-vector(0,hpedestal+tbase/2.,0),
Exemple #14
0
#!/usr/bin/env python

# Author: Raashid Baig <*****@*****.**>
# License: BSD Style.

# Gyroscope hanging from a spring
from math import atan, cos, sin, pi

from enthought.tvtk.tools.visual import vector, MVector, Box, Helix, Frame, \
    Cylinder, curve, color, iterate, show


top = vector(0,1.,0) # where top of spring is held
ks = 100. # spring stiffness
Lspring = 1. # unstretched length of spring
Rspring = 0.03 # radius of spring
Dspring = 0.03 # thickness of spring wire
Lshaft = 1. # length of gyroscope shaft
Rshaft = 0.03 # radius of gyroscope shaft
M = 1. # mass of gyroscope (massless shaft)
Rrotor = 0.4 # radius of gyroscope rotor
Drotor = 0.1 # thickness of gyroscope rotor
Dsquare = 1.4*Drotor # thickness of square that turns with rotor
I = 0.5*M*Rrotor**2. # moment of inertia of gyroscope
omega = 40.0 # angular velocity of rotor along axis
g = 9.8
Fgrav = MVector(0,-M*g,0)
precession = M*g*(Lshaft/2.)/(I*abs(omega)) # exact precession angular velocity
phi = atan(precession**2*(Lshaft/2.)/g) # approximate angle of spring to vertical
s = M*g/(ks*cos(phi)) # approximate stretch of spring
# Refine estimate of angle of spring to vertical:
Exemple #15
0
#!/usr/bin/env python

# Author: Raashid Baig <*****@*****.**>
# License: BSD Style.

# Gyroscope hanging from a spring
from math import atan, cos, sin, pi

from enthought.tvtk.tools.visual import vector, MVector, Box, Helix, Frame, \
    Cylinder, curve, color, iterate, show

top = vector(0, 1., 0)  # where top of spring is held
ks = 100.  # spring stiffness
Lspring = 1.  # unstretched length of spring
Rspring = 0.03  # radius of spring
Dspring = 0.03  # thickness of spring wire
Lshaft = 1.  # length of gyroscope shaft
Rshaft = 0.03  # radius of gyroscope shaft
M = 1.  # mass of gyroscope (massless shaft)
Rrotor = 0.4  # radius of gyroscope rotor
Drotor = 0.1  # thickness of gyroscope rotor
Dsquare = 1.4 * Drotor  # thickness of square that turns with rotor
I = 0.5 * M * Rrotor**2.  # moment of inertia of gyroscope
omega = 40.0  # angular velocity of rotor along axis
g = 9.8
Fgrav = MVector(0, -M * g, 0)
precession = M * g * (Lshaft / 2.) / (I * abs(omega)
                                      )  # exact precession angular velocity
phi = atan(precession**2 * (Lshaft / 2.) /
           g)  # approximate angle of spring to vertical
s = M * g / (ks * cos(phi))  # approximate stretch of spring
Exemple #16
0
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:
        lorenz.extend(pts)
        pts[:] = []

show()
Exemple #17
0
# The Lagrangian variables are polar angle theta,
# azimuthal angle phi, and spin angle alpha.

Lshaft = 1.  # length of gyroscope shaft
Rshaft = 0.03  # radius of gyroscope shaft
M = 1.  # mass of gyroscope (massless shaft)
Rrotor = 0.4  # radius of gyroscope rotor
Drotor = 0.1  # thickness of gyroscope rotor
Dsquare = 1.4 * Drotor  # thickness of square that turns with rotor
I = 0.5 * M * Rrotor**2.  # moment of inertia of gyroscope
hpedestal = Lshaft  # height of pedestal
wpedestal = 0.1  # width of pedestal
tbase = 0.05  # thickness of base
wbase = 3. * wpedestal  # width of base
g = 9.8
Fgrav = vector(0, -M * g, 0)
top = vector(0, 0, 0)  # top of pedestal

theta = pi / 3.  # initial polar angle of shaft (from vertical)
thetadot = 0  # initial rate of change of polar angle
alpha = 0  # initial spin angle
alphadot = 15  # initial rate of change of spin angle (spin ang. velocity)
phi = -pi / 2.  # initial azimuthal angle
phidot = 0  # initial rate of change of azimuthal angle
# Comment in following line to get pure precession
##phidot = (-alphadot+sqrt(alphadot**2+2*M*g*r*cos(theta)/I))/cos(theta)

pedestal = box(pos=top - vector(0, hpedestal / 2., 0),
               height=hpedestal,
               length=wpedestal,
               width=wpedestal,
Exemple #18
0
L2 = 1.0 # physical length of lower bar
L2display = L2+d/2. # show lower bar a bit longer than physical, to overlap axle
# Coefficients used in Lagrangian calculation
A = (1./4.)*M1*L1**2+(1./12.)*M1*L1**2+M2*L1**2
B = (1./2.)*M2*L1*L2
C = g*L1*(M1/2.+M2)
D = M2*L1*L2/2.
E = (1./12.)*M2*L2**2+(1./4.)*M2*L2**2
F = g*L2*M2/2.

hpedestal = 1.3*(L1+L2) # height of pedestal
wpedestal = 0.1 # width of pedestal
tbase = 0.05 # thickness of base
wbase = 8.*gap # width of base
offset = 2.*gap # from center of pedestal to center of U-shaped upper assembly
top = vector(0,0,0) # top of inner bar of U-shaped upper assembly
   
theta1 = 1.3*pi/2. # initial upper angle (from vertical)
theta1dot = 0 # initial rate of change of theta1
theta2 = 0 # initial lower angle (from vertical)
theta2dot = 0 # initial rate of change of theta2
   
pedestal = box(pos = (top - vector(0, hpedestal/2.0, offset)),size = (wpedestal, 1.1*hpedestal, wpedestal), color = (0.4,0.4,0.5))
    
base = box(pos = (top - vector(0,hpedestal + tbase/2.0, offset)),size=(wbase, tbase, wbase),color = (0.4,0.4,0.5))
    
bar1 = box(pos=(L1display/2.0 - d/2.0, 0, -(gap+d)/2.0), size=(L1display, d, d), color=(1,0,0))    
bar1b = box(pos=(L1display/2.0 - d/2.0, 0, (gap+d)/2.0), size=(L1display, d, d), color=(1,0,0))
    
frame1 = frame(bar1, bar1b)
frame1.pos = (0.0, 0.0, 0.0)