Beispiel #1
0
 def __init__(self, x, y, z, dir=(0,-1,0), r=1, thick=.2):
     self.slinky, self.m, self.dir = [], len(x), dir
     for i in range(self.m):
         c = (0.9, 1 - 0.8*i/self.m, 0.1)        # RGB color mix
         self.slinky.append(vp.helix(radius=r, coils=1, color=c,
                                     thickness=thick))
     self.move(x, y, z)
Beispiel #2
0
    def __init__(self, center, radius, normal, I, scene, loops = 1, pitch = 1):
        Shape.__init__(self, scene)

        self.center = center
        self.radius = radius
        self.normal = normal

        self.loops = loops
        self.pitch = pitch
        self.length = loops*pitch

        self.I = I

        # some consonants
        self.C = mu_0*I/pi
        self.oner = [[1,0,0], [0,1,0], [0,0,1]]

        # rotation matrices for this coil, rotating so norm becomes z axis
        self.rotate = self.find_rotmatrix(normal.norm(), vector(0, 0, 1))
        self.antiRotate = inverse(self.rotate)


        if loops == 1:
            self.obj = ring(pos = center, axis = normal*self.length,
                    radius = radius, thickness = 0.1, display = scene,
                    material = materials.chrome)
        else:
            self.obj = helix(pos = center, axis = normal*self.length,
                    radius = radius, coils = loops, thickness = 0.1,
                    display = scene, material = materials.chrome)
Beispiel #3
0
 def sResorte(self):
     self.kR=self.kR.get()
     self.masaR=self.masaR.get()
     try:
         self.kR=float(self.kR)
         self.masaR=float(self.masaR)
     except:
         self.alerta()
     gdpos=vgraph.gdisplay(x=600,y=0,xtitle='Tiempo',ytitle='Posicion')
     plotpos=vgraph.gcurve(gdisplay=gdpos,color=vs.color.red)
     gdvel=vgraph.gdisplay(x=600,y=600,xtitle='Velocidad',ytitle='Tiempo')
     plotvel=vgraph.gcurve(gdisplay=gdvel,color=vs.color.blue)
     gdacl=vgraph.gdisplay(x=0,y=900,xtitle='Aceleracion',ytitle='Tiempo')
     plotacl=vgraph.gcurve(gdisplay=gdacl,color=vs.color.green)
     resorte=vs.helix(pos=(0,5,0),axis=(0,0,-1),radius=0.5,color=vs.color.red)
     resfera=vs.sphere(pos=(0,0,0),radius=0.7,color=vs.color.blue)
     t=0
     while t<=100:
         resorte.axis=(0,-5+3*np.cos(np.sqrt(self.kR/self.masaR)*t),-1)
         resfera.pos=(0,3*np.cos(np.sqrt(self.kR/self.masaR)*t),0)
         plotpos.plot(pos=(t,3*np.cos(np.sqrt(self.kR/self.masaR)*t)))
         plotvel.plot(pos=(t,-3*np.sqrt(self.kR/self.masaR)*np.sin(np.sqrt(self.kR/self.masaR)*t)))
         plotacl.plot(pos=(t,-3*(self.kR/self.masaR)*np.cos(np.sqrt(self.kR/self.masaR)*t)))
         t+=0.01
         vs.rate(100)
Beispiel #4
0
 def __init__(self):
     """Just create the objects."""
     self.spring = vis.helix(pos=(0.0, 0.0, 0.0),
                             axis=vis.vector(1.0, 1.0, 1.0), radius=0.6, color=vis.color.yellow)
     self.ball = vis.sphere(
         pos=(0.0, 0.0, 0.0), radius=1, make_trail = True)
     self.floors=[]
     for i in range(0,5):
         if i%2==0:
             color=vis.color.yellow
         else:
             color= vis.color.white
         self.floors.append(vis.box(size=(5, .01, 2), pos=(5*i, 0, 0),color=color))
Beispiel #5
0
def makespring(natom1, natom2, radius):
    """ make spring from nnth atom to iith atom"""
    if natom1 > natom2:
        r12 = ATOM[natom2].pos-ATOM[natom1].pos
        direct = vp.norm(r12)
        SPRINGS.append(vp.helix(pos=ATOM[natom1].pos+RS*direct,
                                axis=(L-2*RS)*direct,
                                radius=radius,
                                color=SCOLOR, thickness=0.04)) #, shininess=0.9))
        SPRINGS[-1].atom1 = ATOM[natom1]
        SPRINGS[-1].atom2 = ATOM[natom2]
        angle = SPRINGS[-1].axis.diff_angle(vp.vector(0, 1, 0))
        # avoid pathologies if too near the y axis (default "up")
        if angle < 0.1 or angle > PI-0.1:
            SPRINGS[-1].up = vp.vector(-1, 0, 0)
Beispiel #6
0
    def __init__(self, center, radius, normal, I, scene, loops=1, pitch=1):
        Shape.__init__(self, scene)

        self.center = center
        self.radius = radius
        self.normal = normal

        self.loops = loops
        self.pitch = pitch
        self.length = loops * pitch

        self.I = I

        # some consonants
        self.C = mu_0 * I / pi
        self.oner = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]

        # rotation matrices for this coil, rotating so norm becomes z axis
        self.rotate = self.find_rotmatrix(normal.norm(), vector(0, 0, 1))
        self.antiRotate = inverse(self.rotate)

        if loops == 1:
            self.obj = ring(pos=center,
                            axis=normal * self.length,
                            radius=radius,
                            thickness=0.1,
                            display=scene,
                            material=materials.chrome)
        else:
            self.obj = helix(pos=center,
                             axis=normal * self.length,
                             radius=radius,
                             coils=loops,
                             thickness=0.1,
                             display=scene,
                             material=materials.chrome)
Beispiel #7
0
def getapiu():
    """Returns an APIU box at (0,0,0), with sun shields, cable suppports, lid, cable bundles.

     Returned value is a tuple of (apiu, olist) where apiu is the frame containing the APIU, and
     olist is the list of component objects
  """
    apiu = visual.frame()
    # Main APIU box object
    box = visual.box(frame=apiu,
                     pos=V(0, 0, 0.800 / 2 + 0.12),
                     length=0.800,
                     height=1.050,
                     width=0.800,
                     color=color.white)

    # Pyramid shaped lid on box
    hat = visual.pyramid(frame=apiu,
                         pos=V(0, 0, 0.800 + 0.12),
                         size=V(0.06, 1.050, 0.800),
                         axis=V(0, 0, 1),
                         color=color.white)

    # These objects define the I beams that the box is resting on
    rv1 = visual.box(frame=apiu,
                     pos=V(-0.3, 0, 0.055),
                     length=0.01,
                     height=1.250,
                     width=0.10,
                     color=color.white)
    rt1 = visual.box(frame=apiu,
                     pos=V(-0.3, 0, 0.115),
                     length=0.10,
                     height=1.250,
                     width=0.01,
                     color=color.white)
    rb1 = visual.box(frame=apiu,
                     pos=V(-0.3, 0, 0.005),
                     length=0.10,
                     height=1.250,
                     width=0.01,
                     color=color.white)
    rv2 = visual.box(frame=apiu,
                     pos=V(0.3, 0, 0.055),
                     length=0.01,
                     height=1.250,
                     width=0.10,
                     color=color.white)
    rt2 = visual.box(frame=apiu,
                     pos=V(0.3, 0, 0.115),
                     length=0.10,
                     height=1.250,
                     width=0.01,
                     color=color.white)
    rb2 = visual.box(frame=apiu,
                     pos=V(0.3, 0, 0.005),
                     length=0.10,
                     height=1.250,
                     width=0.01,
                     color=color.white)

    # These objects define the sun-shield plates with an air-gap around the sides of the box
    sss = visual.box(frame=apiu,
                     pos=V(0, -1.050 / 2 - 0.030, 0.800 / 2 + 0.12),
                     length=0.800,
                     height=0.003,
                     width=0.800,
                     color=color.white)
    ssn = visual.box(frame=apiu,
                     pos=V(0, 1.050 / 2 + 0.030, 0.800 / 2 + 0.12),
                     length=0.800,
                     height=0.003,
                     width=0.800,
                     color=color.white)
    sse = visual.box(frame=apiu,
                     pos=V(-0.800 / 2 - 0.030, 0, 0.600 / 2 + 0.12),
                     length=0.003,
                     height=1.050,
                     width=0.600,
                     color=color.white)
    ssw = visual.box(frame=apiu,
                     pos=V(0.800 / 2 + 0.030, 0, 0.600 / 2 + 0.12),
                     length=0.003,
                     height=1.050,
                     width=0.600,
                     color=color.white)

    # Add all the above to the component object list:
    olist = [box, hat, rv1, rt1, rb1, rv2, rt2, rb2, sss, ssn, sse, ssw]

    # Create four fibre cable bundles exiting the East side of the APIU
    cbylist = [-0.2775, -0.1255, 0.1255, 0.2775]
    cblist = []
    for cy in cbylist:
        # Bridle support for fibre bundle, with helical cable support
        cblist.append(
            visual.cylinder(frame=apiu,
                            pos=V(-0.800 / 2, cy, 0.700 + 0.120),
                            axis=(-0.100, 0, 0),
                            radius=0.01))
        cblist.append(
            visual.helix(frame=apiu,
                         pos=V(-0.800 / 2 - 0.150, cy, 0.700 + 0.120 - 0.05),
                         axis=(0.05, 0, 0),
                         radius=0.050,
                         thickness=0.01,
                         coils=1,
                         up=(0, 1, 0),
                         color=color.white))
        # Cable bundle itself
        cb, tlist = getbundle(bframe=apiu,
                              spos=V(-0.800 / 2, cy, 0.700 + 0.120 - 0.05))
        cblist += tlist
        cb.rotate(angle=visual.pi,
                  axis=(0, 0, 1),
                  origin=V(-0.800 / 2, cy,
                           0.700 + 0.120 - 0.05))  # Rotate bundle to face East

    # Create four fibre cable bundles exiting the West side of the APIU
    for cy in cbylist:
        # Bridle support for fibre bundle, with helical cable support
        cblist.append(
            visual.cylinder(frame=apiu,
                            pos=V(0.800 / 2, cy, 0.700 + 0.120),
                            axis=(0.100, 0, 0),
                            radius=0.01))
        cblist.append(
            visual.helix(frame=apiu,
                         pos=V(0.800 / 2 + 0.10, cy, 0.700 + 0.120 - 0.05),
                         axis=(0.05, 0, 0),
                         radius=0.050,
                         thickness=0.01,
                         coils=1,
                         up=(0, 1, 0),
                         color=color.white))
        # Cable bundle itself
        cb, tlist = getbundle(bframe=apiu,
                              spos=V(0.800 / 2, cy, 0.700 + 0.120 - 0.05))
        cblist += tlist

    olist += cblist
    return apiu, olist
Beispiel #8
0
#
# Program 6.1: Simple harmonic oscillator (sho.py)
# J Wang, Computational modeling and visualization with Python
#

import visual as vp

ball = vp.sphere(pos=(-2,-2,0), radius=1, color=vp.color.green) # ball
wall = vp.box(pos=(-4,-2,0), length=.2, height=4, width=4)      # wall
floor = vp.box(pos=(0,-3.1,0), length=8, height=0.2, width=4)   # floor 
spring = vp.helix(pos=wall.pos, thickness=0.1, radius=0.5)      # spring 

h, v = 0.1, 0.0                         # step size, initial velocity  
while True:
    vp.rate(50)
    ball.pos.x = ball.pos.x + v*h       
    v = v - ball.pos.x*h                # Euler-Cromer method 
    spring.length = ball.pos.x + 3      # stretch spring (offset by 3) 
       
#
# Program 6.5: Triatomic vibrations (triatom.py)
# J Wang, Computational modeling and visualization with Python
#

import visual as vp, numpy as np

def accel(u):
    return -k*np.array([u[0]-u[1], 2*u[1]-u[0]-u[2], u[2]-u[1]])/m

col = [(1,0,0), (0,1,0), (0,0,1)]           # RGB colors
x0, atom, r = np.array([-3., 0., 3.]), [0]*3, 1.0
for i in range(3):
    atom[i] = vp.sphere(pos=(x0[i],0,0), radius=r, color=col[i]) # atoms
floor = vp.box(pos=(0,-1.1,0), length=8, height=0.2, width=4)    # floor 
s1 = vp.helix(pos=(x0[0],0,0), thickness=0.1, radius=0.5)        # spring
s2 = vp.helix(pos=(x0[1],0,0), thickness=0.1, radius=0.5)

h, k, m = 0.1, 1.0, np.array([1./4, 2./5, 1./4])
u, v = np.array([-1.,0.,1.]), np.zeros(3)   # symmetric init cond
while True:
    vp.rate(50)
    u = u + v*h                             # Euler-Cromer method
    v = v + accel(u)*h
    x = x0 + u
    for i in range(3):                      # animation
        atom[i].pos = (x[i],0,0)
    s1.axis, s1.pos, s1.length= (1,0,0), x[0]+r, x[1]-x[0]-2*r   # move 
    s2.axis, s2.pos, s2.length= (1,0,0), x[1]+r, x[2]-x[1]-2*r