예제 #1
0
파일: vpmnb.py 프로젝트: com-py/compy
 def __init__(self, x, y, z, dir=vec(0,-1,0), r=1, thick=.2):
     self.slinky, self.m, self.dir = [], len(x), dir
     for i in range(self.m):
         c = vec(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)
예제 #2
0
 def __init__(self, x, y, z, dir=vec(0, -1, 0), r=1, thick=.2):
     self.slinky, self.m, self.dir = [], len(x), dir
     for i in range(self.m):
         c = vec(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)
 def _initialize(self, threshold):
     # Construct and place all atoms.
     for _, position, force in self.cell_obj.atom_list:
         atom = vp.sphere(pos=position, radius=0.35,
                 vel=vp.vector(0.,0.,0.), mass=1.0, initial_force=vp.vector(0.,0.,0),
                 make_trail=False, initial_pos=position, force_constant=force,
                 label=position.x+position.y+position.z)
         self.atom_list.append(atom)
     
     # Construct and place all springs between the atoms if they're within the lattice distance.
     for atom in self.atom_list:
         for connect in self.atom_list[:-1]:
             # if the atom connection exists, skip.
             exists = False
             for spring in self.spring_list:
                 if (spring.atom_one == atom and spring.atom_two == connect) or (spring.atom_one == connect and spring.atom_two == atom) or atom == connect:
                     exists = True
             if exists:
                 continue
             
             # Check distance is between threshold.
             separation = (atom.pos - connect.pos).mag
             if separation == 0.0:
                 continue
             
             if (separation <= threshold):
                 # Attach a spring between every atom unless specified otherwise.
                 self.spring_list.append(vp.helix(pos=atom.pos, atom_one=atom, atom_two=connect, eq_len=separation,
                                             axis=(connect.pos-atom.pos), radius=0.25, force_constant=atom.force_constant,
                                                 coils=atom.force_constant+4))
예제 #4
0
파일: atomic_grid.py 프로젝트: PauliSpin/3D
 def make_spring(self, start, end, visible):
     spring = vp.helix()
     spring.pos = start.pos
     spring.axis = end.pos-start.pos
     spring.visible = visible
     spring.thickness = 0.05
     spring.radius = 0.5*atom_radius
     spring.length = spacing
     spring.start = start
     spring.end = end
     spring.color = vp.color.orange
     self.springs.append(spring)
예제 #5
0
    def create_vis(self, canvas=None):
        """
        Creates a visualisation. By default, uses a vpython canvas, so imports vpython.
        Subclass class and change this to change the way visualisations are made.
        Parameters
        ----------
        canvas: vpython canvas
            display into which the visualization is drawn
        """
        import vpython
        #self.scene stores the display into which the system draws
        if not canvas:
            if not self.scene:
                self.scene = vpython.canvas()
        if canvas:
            self.scene = canvas

        # Draw particles if they aren't drawn yet
        for particle in self.particles:
            if not particle._visualized:
                self.spheres.append(vpython.sphere(pos=vector_from(particle.pos),
                    radius=particle.radius,
                    color=vector_from(particle.color),
                    opacity=particle.alpha,
                    display=self.scene))
                particle._visualized = True
        # Draw springs if they aren't drawn yet
        for spring in self.springs:
            if not spring._visualized:
                self.helices.append(vpython.helix(pos=vector_from(spring.particle_1.pos),
                    axis=vector_from(spring.axis),
                    radius=spring.radius,
                    opacity=spring.alpha,
                    color=vector_from(spring.color),
                    display=self.scene))
                spring._visualized = True
        # Draw pointers if they aren't drawn yet
        for pointer in self.pointers:
            if not pointer._visualized:
                self.arrows.append(vpython.arrow(pos=vector_from(pointer.pos),
                    axis=vector_from(pointer.axis),
                    shaftwidth=pointer.shaftwidth,
                    opacity=pointer.alpha,
                    color=vector_from(pointer.color),
                    display=self.scene))
                pointer._visualized = True
 def __init__(self, radius, r0, v0):
     # Create a mass
     mass = vp.sphere()
     mass.pos = r0
     mass.radius = radius
     mass.velocity = v0
     mass.color = vp.vector(0, 0.56, 0.61)
     self.mass = mass
     # Create a spring
     spring = vp.helix()
     spring.pos = vp.vector(0, 0, 0)
     spring.axis = mass.pos
     spring.thickness = 0.05
     spring.radius = 0.3 * radius
     spring.color = vp.color.orange
     self.spring = spring
     self.amplitude = vp.vector(0, 0, 0)  # oscillator property
    def _init_anim(self):
        import vpython as vp
        c = 0.1*self.obs_space.bound_up[0]

        self._anim['canvas'] = vp.canvas(width=1000, height=400, title="One Mass Oscillator")
        self._anim['ground'] = vp.box(
            pos=vp.vec(0, -0.02, 0),
            length=2.*self.obs_space.bound_up[0],
            height=0.02,
            width=3*c,
            color=vp.color.green,
            canvas=self._anim['canvas']
        )
        self._anim['mass'] = vp.box(
            pos=vp.vec(self.state[0], c/2., 0),
            length=c,
            height=c,
            width=c,
            color=vp.color.blue,
            canvas=self._anim['canvas']
        )
        self._anim['des'] = vp.box(
            pos=vp.vec(self._task.state_des[0], 0.8*c/2., 0),
            length=0.8*c,
            height=0.8*c,
            width=0.8*c,
            color=vp.color.cyan,
            opacity=0.5,  # 0 is fully transparent
            canvas=self._anim['canvas']
        )
        self._anim['force'] = vp.arrow(
            pos=vp.vec(self.state[0], c/2., 0),
            axis=vp.vec(0.1*self._curr_act, 0, 0),
            color=vp.color.red,
            shaftwidth=0.2*c,
            canvas=self._anim['canvas']
        )
        self._anim['spring'] = vp.helix(
            pos=vp.vec(0, c/2., 0),
            axis=vp.vec(self.state[0] - c/2., 0, 0),
            color=vp.color.blue,
            radius=c/3.,
            canvas=self._anim['canvas']
        )
예제 #8
0
def init_spring_and_ball():
    # Draw a box to anchor the spring, but don't bother naming or returning it.
    # It does not change over time.
    box_size = 20
    # Position is the center of the box. We want the edge at the origin.
    box_center = vpython.vector(-0.5 * box_size, 0, 0)
    vpython.box(
        # Position is the center of the box. We want the edge at the origin.
        pos=box_center,
        width=box_size,
        length=box_size,
        height=box_size,
        texture=vpython.textures.stucco,
    )
    # VPython objects are initialized with their display attributes. We can
    # then add additional attributes for convenient bookkeeping.
    spring_length_relax = 10
    spring_length_start = 5
    spring_axis = vpython.vector(spring_length_start, 0, 0)
    spring = vpython.helix(
        pos=vpython.vector(0, 0, 0),
        coils=10,
        axis=spring_axis,
    )
    spring.spring_constant = 1
    spring.length_relax = spring_length_relax
    # Same deal for the ball. Position, radius, and color are all we need to
    # draw the initial object. Additional values are used later.
    ball_radius = 1
    ball = vpython.sphere(
        pos=spring.axis,
        radius=ball_radius,
        color=vpython.color.red,
    )
    ball.mass = 1
    ball.velocity = vpython.vector(0, 0, 0)
    return spring, ball
condINI=array([thetaI,thetaIp,phiI,phiIp])
sol=odeint(solucion,condINI,t,args=(g,l,k,m))
xp=l*thetaI
yp=-l
zp=0
r=1



pendulo1=sphere(pos=vector(xp,yp,zp),radius=r,color=color.green)
pendulo2=sphere(pos=vector(xp+l,yp,zp),radius=r,color=color.green)
#cuerda1=curve(vector(0,0,0),pendulo1.pos)
#cuerda2=curve(vector(l,0,0),pendulo2.pos)

cuerdas1=cylinder(pos=pendulo2.pos,axis=vector(0,0,0),radius=0.1,color=color.white)
cuerdas2=cylinder(pos=pendulo2.pos,axis=vector(l,0,0),radius=0.1,color=color.white)
base=box(pos=vector(l/2,0,0),size=vector(l+2,0.1,0.1),color=color.orange)
spring=helix(pos=pendulo2.pos,axis=vector(0,0,0),radius=0.3,constant=k,thickness=0.1,coils=10,color=color.white)
ti=0
while ti<tf:
    sleep(0.01)
    pendulo1.pos=vector(l*sol[ti,0],yp,zp)
    pendulo2.pos=vector(l*sol[ti,2]+l,yp,zp)
    cuerdas2.pos=pendulo2.pos
    cuerdas2.axis=vector(l,0,0)-cuerdas2.pos
    cuerdas1.pos=pendulo1.pos
    cuerdas1.axis=vector(0,0,0)-cuerdas1.pos
    spring.pos=pendulo1.pos
    spring.axis=pendulo2.pos-spring.pos
    ti = ti + 1
예제 #10
0
 def initGraphics(self):
     self.helix = helix(pos=vector(0, 0, 0),
                        axis=vector(1, 0, 0),
                        radius=self.radius,
                        coils=self.coils)
예제 #11
0
pendulo1 = sphere(pos=vector(xp, yp, zp),
                  radius=r,
                  color=color.yellow,
                  make_trail=True)  #,trail_type="points")
pendulo2 = sphere(pos=vector(xp + l, yp, zp),
                  radius=r,
                  color=color.red,
                  make_trail=True)  #,trail_type="points")
cuerda1 = curve(vector(0, 0, 0), pendulo1.pos)
cuerda2 = curve(vector(l, 0, 0), pendulo2.pos)
base = box(pos=vector(l / 2, 0, 0),
           size=vector(l, 0.1, 0.1),
           color=color.magenta)
spring = helix(pos=pendulo1.pos,
               axis=pendulo2.pos - pendulo1.pos,
               radius=0.3,
               constant=k,
               thickness=0.1,
               coils=6,
               color=color.white)
ti = 0
while ti < tf:
    sleep(0.01)
    pendulo1.pos = vector(l * sol[ti, 0], yp, zp)
    pendulo2.pos = vector(l * sol[ti, 2] + l, yp, zp)
    cuerda1 = curve(vector(0, 0, 0), pendulo1.pos)
    cuerda2 = curve(vector(l, 0, 0), pendulo2.pos)
    spring.pos = pendulo1.pos
    spring.axis = pendulo2.pos - spring.pos
    ti = ti + 1
예제 #12
0
        color=vp.color.green,
        opacity=0.3)
vp.ring(pos=vp.vector(.2, 0, 0),
        radius=.6,
        axis=vp.vector(1, 0, 0),
        thickness=0.12,
        color=vp.color.gray(0.4))
vp.ellipsoid(pos=vp.vector(-.3, 2, 0),
             color=vp.color.orange,
             size=vp.vector(.3, 1.5, 1.5))
vp.pyramid(pos=vp.vector(.3, 2, 0),
           color=vp.vector(0, 0.5, .25),
           size=vp.vector(0.8, 1.2, 1.2))
spring = vp.helix(pos=vp.vector(2, -1.25, 0),
                  radius=0.3,
                  axis=vp.vector(0, 1.8, 0),
                  color=vp.color.orange,
                  thickness=.1)
angle = 0
da = .01

trail = vp.curve(color=vp.color.magenta, radius=.02)
trail.append(vp.vector(1, 0, 0))
trail.append(vp.vector(1, 0, 2))
trail.append(vp.vector(2, 0, 2))

while angle < 3 * vp.pi / 4:
    vp.rate(100)
    ptr.rotate(angle=da, axis=vp.vector(0, 0, 1), origin=ptr.pos)
    trail.append(ptr.pos + ptr.axis)
    angle += da
예제 #13
0
T = 295.
eta = 0.954e-3  # Viscosité de l'eau
rayon_part = 200E-12
D = Kb*T/(6*np.pi*eta*rayon_part)
wall_width = 0.01
# object pos
init_pos = v.vector(0, 0, 0)
sphere_pos = v.vector(0, 0, 5)
helix_pos = v.vector(0, 0, 0)
box_back = v.vector(0, 0, -10)
box_bottom = v.vector(0, -5, -5)
box_top = v.vector(0, 5, -5)
box_left = v.vector(-5, 0, -5)
box_right = v.vector(5, 0, -5)
s = v.sphere(pos=sphere_pos, color=v.color.magenta, radius=2.5)
spring = v.helix(pos=helix_pos, color=v.color.green, axis=s.pos, coils=5, thickness=0.1, constant=1)
# x = v.arrow(pos=init_pos + v.vector(5, 5, 0), axis=v.vector(10, 0, 0), color=v.color.blue)
# y = v.arrow(pos=init_pos+ v.vector(5, 5, 0), axis=v.vector(0, 10, 0), color=v.color.green)
# z = v.arrow(pos=init_pos+ v.vector(5, 5, 0), axis=v.vector(0, 0, 10), color=v.color.red)

# my_box_left = v.box(pos=box_left, length=wall_width, height=10, width=10, color=v.color.yellow, opacity=0.5)
# my_box_right = v.box(pos=box_right, length=wall_width, height=10, width=10, color=v.color.yellow, opacity=0.5)
# my_box_front = v.box(pos=init_pos, length=10, height=10, width=wall_width, color=v.color.yellow, opacity=0.5)
# my_box_back = v.box(pos=box_back, length=10, height=10, width=wall_width, color=v.color.yellow, opacity=0.5)
# my_box_bottom = v.box(pos=box_bottom, length=10, height=wall_width, width=10, color=v.color.yellow, opacity=0.5)
# my_box_top = v.box(pos=box_top, length=10, height=wall_width, width=10, color=v.color.yellow, opacity=0.5)
stator_number = 8
stator_r = 0.1  # 1 = 10 nm
stator_thickness = 0.03
# 1er biais : Mauvaise valeur de D possible
# turn_per_nanosec = 1/dt
예제 #14
0
파일: spring.py 프로젝트: DuaneNielsen/odes
from copy import copy

kinetic = gcurve(color=color.blue)
potential = gcurve(color=color.red)
energy = gcurve(color=color.black)
thermal = gcurve(color=color.green)

m = 2  # kg
k = 4  # N/m
d = 2

t = 0
dt = 0.01  # s

s = sphere()
spring = helix(radius=0.6, thickness=0.3)

s.velocity = vector(-10, 0, 0)
s.pos = vector(10, 0, 0) * dt  # m
s.prev_pos = s.pos - s.velocity * dt  # m

thermal_energy = 0

while t < 12.0 * pi:
    kinetic_energy = 0.5 * m * dot(s.velocity, s.velocity)
    potential_energy = 0.5 * k * dot(s.prev_pos, s.prev_pos)
    thermal_energy += d * dot(s.velocity, s.velocity) * dt

    s.force = -k * s.pos - d * s.velocity + 3.0 * sin(1.0 * t) * vector(
        1, 0, 0)
    temp = copy(s.prev_pos)
예제 #15
0
b = 200.  # Final do intervalo da variavel independente

scene.width = 1200  # Ajustando a largura da cena
scene.height = 1000  # Ajustando a altura da cena
scene.camera.pos = vector(2, -1, 2)
scene.camera.axis = vector(-2, 1, -2)

suporte = box(pos=vector(.0, .05, .0),
              up=vector(.0, 1., .0),
              length=2,
              height=.1,
              width=2,
              texture=textures.wood)  # Suporte

mola = helix(pos=vector(0, 0, 0),
             axis=vector(*r_vrl),
             color=color.yellow,
             radius=.03)  # Mola do pendulo

bola = sphere(axis=vector(*r_vrl), radius=.1, make_trail=True)  # Bola

# Constantes

C = 1.

while t <= b:
    rate(C / h)
    mola.axis = vector(*r_vrl)
    bola.pos = vector(*r_vrl)
    r_vrl, v_vrl, vpm = passo_vrl(f, r_vrl, v_vrl, vpm, t, h)
    t += h