コード例 #1
0
    def set_force(self, force, scale=1e-1, f_min=0.1, f_max=10.):
        """

        :param force: 3*2 states force
        :param scale: scaling in velocity
        :param f_min: minimal magnitude of force
        :param f_max: maximal magnitude of force
        """
        global game_objects
        orig = [force[:, 0], force[:, 1], force[:, 2]]
        ff = [force[:, 3] * scale, force[:, 4] * scale, force[:, 5] * scale]
        for ii in range(len(ff[0])):
            magn = vis.sqrt(ff[0][ii] * ff[0][ii] + ff[1][ii] * ff[1][ii] +
                            ff[2][ii] * ff[2][ii]) + 1e-3
            if magn > f_max:
                ff[0][ii] = ff[0][ii] * f_max / magn
                ff[1][ii] = ff[1][ii] * f_max / magn
                ff[2][ii] = ff[2][ii] * f_max / magn
            if magn < f_min:
                ff[0][ii] = ff[0][ii] * f_min / magn
                ff[1][ii] = ff[1][ii] * f_min / magn
                ff[2][ii] = ff[2][ii] * f_min / magn

        v = Vector_dyn(orig,
                       ff,
                       'F',
                       self.p,
                       pos=(0, 0, 0),
                       axis=(5, 0, 0),
                       shaftwidth=0.5,
                       color=vis.color.red)
        game_objects.append(v)
コード例 #2
0
def earth(y, t):# return the eqns of motion
    
    dydt = np.zeros(4)
    dydt[0] = y[2]      # velocity, dr/dt
    dydt[1] = y[3] 
    r = vp.sqrt(y[0]*y[0] + y[1]*y[1]) # acceleration, dv/dt
    dydt[2] = -GM*y[0]/(r*r*r)  
    dydt[3] = -GM*y[1]/(r*r*r)
    return dydt
コード例 #3
0
ファイル: vpython_3d.py プロジェクト: skidzo/mubosym
    def set_force(self, force, scale=1e-1, f_min = 0.1, f_max = 10.):
        """

        :param force: 3*2 states force
        :param scale: scaling in velocity
        :param f_min: minimal magnitude of force
        :param f_max: maximal magnitude of force
        """
        global game_objects
        orig = [force[:,0],force[:,1],force[:,2]]
        ff = [force[:,3]*scale,force[:,4]*scale,force[:,5]*scale]
        for ii in range(len(ff[0])):
            magn = vis.sqrt(ff[0][ii]*ff[0][ii]+ff[1][ii]*ff[1][ii]+ff[2][ii]*ff[2][ii])+1e-3
            if magn > f_max:
                ff[0][ii] = ff[0][ii] * f_max/magn
                ff[1][ii] = ff[1][ii] * f_max/magn
                ff[2][ii] = ff[2][ii] * f_max/magn
            if magn < f_min:
                ff[0][ii] = ff[0][ii] * f_min/magn
                ff[1][ii] = ff[1][ii] * f_min/magn
                ff[2][ii] = ff[2][ii] * f_min/magn

        v = Vector_dyn(orig, ff, 'F', self.p, pos=(0,0,0), axis=(5,0,0), shaftwidth=0.5, color=vis.color.red)
        game_objects.append( v )
コード例 #4
0
ファイル: crystal.py プロジェクト: GadgetSteve/vpython-wx
        atm.near = tuple(atm.near)
        atm.wallpos = tuple(atm.wallpos)
        # Nearpos is a list of references to the nearest neighbors' positions,
        # taking into account wall effects.
        atm.nearpos = []
        for i in range(6):
            natom = atm.near[i]
            if natom is None: # if this nearest neighbor is the wall
                atm.nearpos.append(atm.wallpos[i])
            else:
                atm.nearpos.append(ATOM[natom].pos)

    return ATOM

SRADIUS = R/3.
VRANGE = 0.2*L* vp.sqrt(K/M)
DT = 0.02*(2.*PI* vp.sqrt(M/K))
ATOM = crystal(index=INDEX, delta=L, radius=R, sradius=SRADIUS)
vp.scene.autoscale = False

PTOTAL = vp.vector()
for a in ATOM:
    px = M*(-VRANGE/2+VRANGE*random())
    py = M*(-VRANGE/2+VRANGE*random())
    pz = M*(-VRANGE/2+VRANGE*random())
    a.p = vp.vector(px, py, pz)
    PTOTAL = PTOTAL+a.p

for a in ATOM:
    a.p = vp.array(a.p-PTOTAL/(INDEX**2))
コード例 #5
0
ファイル: drape.py プロジェクト: GadgetSteve/vpython-wx
        BAND.pos[:, 1] = vp.where(BELOW, -1, BAND.pos[:, 1])

    # need a more physical way to make 'damped springs' than this!
    BAND.p = BAND.p * DAMP

    #band.p[0] = 0   # nail down left endpoint
    #band.p[-1] = 0  # nail down right endpoint

    BAND.pos = BAND.pos + BAND.p/M*DT

    #gravity
    BAND.p[:, 1] = BAND.p[:, 1] - M * G * DT

    # force[n] is the force on point n from point n+1 (to the right):
    LENGTH = (BAND.pos[1:] - BAND.pos[:-1])
    DIST = vp.sqrt(vp.sum(LENGTH*LENGTH, -1))
    FORCE = K * (DIST - RESTLENGTH)
    FORCE = LENGTH/DIST[:, vp.newaxis] * FORCE[:, vp.newaxis]

    BAND.p[:-1] = BAND.p[:-1] + FORCE*DT
    BAND.p[1:] = BAND.p[1:] - FORCE*DT

    # color based on "stretch":  blue -> white -> red
    C = vp.clip(DIST/RESTLENGTH * 0.5, 0, 2)

    #   blue (compressed) -> white (relaxed) -> red (tension)
    BAND.red[1:] = vp.where(vp.less(C, 1), C, 1)
    BAND.green[1:] = vp.where(vp.less(C, 1), C, 2-C)
    BAND.blue[1:] = vp.where(vp.less(C, 1), 1, 2-C)

    for S in SPHERES:
コード例 #6
0
ファイル: halley.py プロジェクト: Ahemmetter/comp-physics
	"""
    return -(4 * vi.pi**2 * (r2 - r1) / (vi.mag(r2 - r1)**3))


#Sonne:
sun = vi.sphere(material=vi.materials.emissive, color=vi.color.yellow, \
radius=0.5)
sp = vi.vector(0, 0, 0)  #Koordinatenursprung

#Erde: (eine Einheit = 1AU)
e1 = 0.017  #Exzentrität der Erdumlaufbahn
aphel1 = (e1 + 1) * 1
ep = vi.vector(aphel1, 0, 0)  #Position der Erde
earth = vi.sphere(pos=ep, material=vi.materials.earth, radius=0.2)
earth.trail = vi.curve(color=vi.color.green)  #Trajektorie der Erde
ve = vi.sqrt(4 * vi.pi**2 * (2 / vi.mag(ep) - 1 / 1)) * vi.vector(0, 0, -1)

#Halley'scher Komet:
e2 = 0.97  #verglichen mit der Erde stark elliptisch
aphel2 = (e2 + 1) * 17.94
cp = vi.vector(aphel2, 0, 0)
comet = vi.sphere(pos=cp, color=vi.color.white, radius=0.1)
comet.trail = vi.curve(color=comet.color)  #Trajektorie des Kometen
vc = vi.sqrt(4 * vi.pi ** 2 * (2 / vi.mag(cp) - 1 / 17.94)) * \
vi.vector(0, 0, -1)

vi.scene.autoscale = False

dt = 0.001  #kleine Zeitabstände
i = 0
cometTrail = True
コード例 #7
0
        BAND.pos[:, 1] = vp.where(BELOW, -1, BAND.pos[:, 1])

    # need a more physical way to make 'damped springs' than this!
    BAND.p = BAND.p * DAMP

    #band.p[0] = 0   # nail down left endpoint
    #band.p[-1] = 0  # nail down right endpoint

    BAND.pos = BAND.pos + BAND.p / M * DT

    #gravity
    BAND.p[:, 1] = BAND.p[:, 1] - M * G * DT

    # force[n] is the force on point n from point n+1 (to the right):
    LENGTH = (BAND.pos[1:] - BAND.pos[:-1])
    DIST = vp.sqrt(vp.sum(LENGTH * LENGTH, -1))
    FORCE = K * (DIST - RESTLENGTH)
    FORCE = LENGTH / DIST[:, vp.newaxis] * FORCE[:, vp.newaxis]

    BAND.p[:-1] = BAND.p[:-1] + FORCE * DT
    BAND.p[1:] = BAND.p[1:] - FORCE * DT

    # color based on "stretch":  blue -> white -> red
    C = vp.clip(DIST / RESTLENGTH * 0.5, 0, 2)

    #   blue (compressed) -> white (relaxed) -> red (tension)
    BAND.red[1:] = vp.where(vp.less(C, 1), C, 1)
    BAND.green[1:] = vp.where(vp.less(C, 1), C, 2 - C)
    BAND.blue[1:] = vp.where(vp.less(C, 1), 1, 2 - C)

    for S in SPHERES: