Beispiel #1
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
Beispiel #2
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
 def start_animation(self):
     self.animator = visual.iterate(240, self.animate)
     visual.show()
     return self.animator
Beispiel #4
0
bar2 = box(pos = (L2display/2.0 - d/2.0, 0, 0), size = (L2display, d, d), color = (0,1,0))

frame2 = frame(bar2)
frame2.pos = (0.0, -1.0*L1, 0.0)
frame2.axis = (0.0, -1.0, 0.0)
frame2.rotate(axis = (0,0,1), angle = 180.0*theta2/pi)

dt = 0.001

def anim():
    global theta1, theta2, theta1dot, theta2dot
    atheta1 = ((E*C/B)*sin(theta1)-F*sin(theta2))/(D-E*A/B)
    atheta2 = -(A*atheta1+C*sin(theta1))/B

    theta1dot = theta1dot + atheta1*dt
    theta2dot = theta2dot + atheta2*dt

    dtheta1 = theta1dot*dt
    dtheta2 = theta2dot*dt
    theta1 = theta1 + dtheta1
    theta2 = theta2 + dtheta2

    frame1.rotate(axis = (0,0,1), angle = 180.0*dtheta1/pi)

    frame2.pos = top + frame1.axis*L1
    frame2.rotate(axis = (0,0,1), angle = 180*dtheta2/pi)

a = iterate(20, anim)
a.edit_traits()
show()
Beispiel #5
0
muro_r = visual.box( pos=(ancho+grosor/2., largo/2., 0.0), \
size=(grosor, largo + 2*grosor, grosor), \
color=(0.6, 0.3, 0.0) )
muro_d = visual.box( pos=(ancho/2., -grosor/2., 0.0), \
size=(ancho + 2*grosor, grosor, grosor), \
color=(0.6, 0.3, 0.0) )
muro_u = visual.box( pos=(ancho/2., largo+grosor/2., 0.0), \
size=(ancho + 2*grosor, grosor, grosor), \
color=(0.6, 0.3, 0.0) )


#ITERACION DEL SISTEMA
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)


a = visual.iterate(10, anim)
visual.show()
 def start_animation(self):
     a = visual.iterate(20, self.anim)
     visual.show()
     return a
Beispiel #7
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


a = iterate(40, anim)
a.edit_traits()
show()
Beispiel #8
0
frame2 = frame(bar2)
frame2.pos = (0.0, -1.0 * L1, 0.0)
frame2.axis = (0.0, -1.0, 0.0)
frame2.rotate(axis=(0, 0, 1), angle=180.0 * theta2 / pi)

dt = 0.001


def anim():
    global theta1, theta2, theta1dot, theta2dot
    atheta1 = ((E * C / B) * sin(theta1) - F * sin(theta2)) / (D - E * A / B)
    atheta2 = -(A * atheta1 + C * sin(theta1)) / B

    theta1dot = theta1dot + atheta1 * dt
    theta2dot = theta2dot + atheta2 * dt

    dtheta1 = theta1dot * dt
    dtheta2 = theta2dot * dt
    theta1 = theta1 + dtheta1
    theta2 = theta2 + dtheta2

    frame1.rotate(axis=(0, 0, 1), angle=180.0 * dtheta1 / pi)

    frame2.pos = top + frame1.axis * L1
    frame2.rotate(axis=(0, 0, 1), angle=180 * dtheta2 / pi)


a = iterate(20, anim)
a.edit_traits()
show()
Beispiel #9
0
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)
        # 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

a = iterate(40, anim)
a.edit_traits()
show()
color=(0.6, 0.3, 0.0) )
muro_r = visual.box( pos=(ancho+grosor/2., largo/2., 0.0), \
size=(grosor, largo + 2*grosor, grosor), \
color=(0.6, 0.3, 0.0) )
muro_d = visual.box( pos=(ancho/2., -grosor/2., 0.0), \
size=(ancho + 2*grosor, grosor, grosor), \
color=(0.6, 0.3, 0.0) )
muro_u = visual.box( pos=(ancho/2., largo+grosor/2., 0.0), \
size=(ancho + 2*grosor, grosor, grosor), \
color=(0.6, 0.3, 0.0) )


#ITERACION DEL SISTEMA
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 )

a = visual.iterate(10, anim)
visual.show()
Beispiel #11
0
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)
        p = a.orbit.points
        if len(p) > 1000:
            a.orbit.points = p[200:]


a = iterate(50, anim)
a.edit_traits()
show()
Beispiel #12
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)
        p = a.orbit.points
        if len(p) > 1000:
            a.orbit.points = p[200:]

a = iterate(50, anim)
a.edit_traits()
show()
Beispiel #13
0
def main():
    dt = 0.1

    x = arange(-50,50)
    wpoints1 = zeros((100,3), float)
    wpoints2 = zeros((100,3), float)
    wpoints3 = zeros((100,3), float)
    wpoints4 = zeros((100,3), float)

    for i in range (0,100,1):
        wpoints1[i] = [x[i], -30, 0]
        wpoints2[i] = [x[i], -15, 0]
        wpoints3[i] = [x[i], 0, 0]
        wpoints4[i] = [x[i], 15, 0]

    band1 = Curve(points = wpoints1, k = 6.0, color = (1,0,0),
                  mass = 2.0, radius = 0.5, momentum = zeros((100, 3), float))

    band2 = Curve(points = wpoints2, k = 6.0, color = (1,1,0),
                  mass = 2.0, radius = 0.5, momentum = zeros((100, 3), float))

    band3 = Curve(points = wpoints3, k = 6.0, color = (0,1,0),
                  mass = 2.0, radius = 0.5, momentum = zeros((100, 3), float))

    band4 = Curve(points = wpoints4, k = 6.0, color = (0,0,1),
                  mass = 2.0, radius = 0.5, momentum = zeros((100, 3), float))

    for i in range(0,25,1):
        band1.momentum[i,1] = sin(x[i]*pi/25.0)*3   # half-wave pulse

    for i in range(0,25,1):
        band2.momentum[i,1] = sin(x[i]*2*pi/25.0)*5   # full-wave pulse

    for i in range(0,25,1):
        band3.momentum[i,0] = sin(x[i]*pi/25.0)*5   # compresion pulse

    for i in range(0,100,1):
        band4.momentum[i,1] = sin(x[i]*4*pi/100.0)*2   # standing wave

    def anim():
        band1.momentum[0] = band1.momentum[-1] = MVector(0,0,0)
        band2.momentum[0] = band2.momentum[-1] = MVector(0,0,0)
        band3.momentum[0] = band3.momentum[-1] = MVector(0,0,0)
        band4.momentum[0] = band4.momentum[-1] = MVector(0,0,0)

        band1.points = band1.points + (band1.momentum/band1.mass*dt)
        band2.points = band2.points + (band2.momentum/band2.mass*dt)
        band3.points = band3.points + (band3.momentum/band3.mass*dt)
        band4.points = band4.points + (band4.momentum/band4.mass*dt)

        force1 = band1.k * (band1.points[1:] - band1.points[:-1])
        force2 = band2.k * (band2.points[1:] - band2.points[:-1])
        force3 = band3.k * (band3.points[1:] - band3.points[:-1])
        force4 = band4.k * (band4.points[1:] - band4.points[:-1])

        band1.momentum[:-1] = band1.momentum[:-1] + force1 * dt
        band2.momentum[:-1] = band2.momentum[:-1] + force2 * dt
        band3.momentum[:-1] = band3.momentum[:-1] + force3 * dt
        band4.momentum[:-1] = band4.momentum[:-1] + force4 * dt

        band1.momentum[1:] = band1.momentum[1:] - force1 * dt
        band2.momentum[1:] = band2.momentum[1:] - force2 * dt
        band3.momentum[1:] = band3.momentum[1:] - force3 * dt
        band4.momentum[1:] = band4.momentum[1:] - force4 * dt

    a = iterate(20, anim)
    show()
    return a
Beispiel #14
0
 def start_animation(self):
     a = visual.iterate(20, self.anim)
     visual.show()
     return a
 def start_animation(self):
     self.animator = visual.iterate(60, self.animate)
     visual.show()
     return self.animator