def sCaidalibre(self): self.alturaCL=self.alturaCL.get() self.velocidadX=self.velocidadX.get() try: self.alturaCL=float(self.alturaCL) self.velocidadX=float(self.velocidadX) except: self.alerta() gdpos=vgraph.gdisplay(x=600,y=0,xtitle='Tiempo',ytitle='Posicion(y)') 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.blue) suelo=vs.box(pos=(0,-5,0),length=30,height=0.1,width=1,color=vs.color.blue) esferaC=vs.sphere(pos=(0,self.alturaCL,-2),radius=1,color=vs.color.red) T=np.sqrt(2*(self.alturaCL+5)/9.8) t=0 while t<T: esferaC.pos=(self.velocidadX*t,self.alturaCL-9.8*t**2/2,-2) plotpos.plot(pos=(t,self.alturaCL-9.8*t**2/2)) plotvel.plot(pos=(t,-9.8*t)) plotacl.plot(pos=(t,-9.8)) t+=0.001 vs.rate(100)
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)
def sEnergia(self): self.alturaE=self.alturaE.get() self.masaE=self.masaE.get() try: self.alturaE=float(self.alturaE) self.masaE=float(self.masaE) except: self.alerta() gdenergia=vgraph.gdisplay(x=600,y=0,xtitle='Tiempo',ytitle='Energia') plotpot=vgraph.gcurve(gdisplay=gdenergia,color=vs.color.green) plotcin=vgraph.gcurve(gdisplay=gdenergia,color=vs.color.red) plottot=vgraph.gcurve(gdisplay=gdenergia,color=vs.color.blue) sueloE=vs.box(pos=(0,-1,0),length=30,height=0.1,width=1,color=vs.color.blue) esferaE=vs.sphere(pos=(0,self.alturaE,-2),radius=1,color=vs.color.red) T=np.sqrt(2*(self.alturaE)/9.8) t=0 while t<=T: esferaE.pos=(0,self.alturaE-9.8*t**2/2,-2) plotpot.plot(pos=(t,9.8*self.masaE*(self.alturaE-9.8*t**2/2))) plotcin.plot(pos=(t,self.masaE*(9.8*t)**2/2)) plottot.plot(pos=(t,9.8*self.masaE*(self.alturaE-9.8*t**2/2)+self.masaE*(9.8*t)**2/2)) t+=0.01 vs.rate(100)
C Bordeianu, Univ Bucharest, 2017. Please respect copyright & acknowledge our work.""" # SplineInteract.py Spline fit with slide to control number of points from visual import *; from visual.graph import *; from visual.graph import gdisplay, gcurve from visual.controls import slider, controls, toggle x = array([0., 0.12, 0.25, 0.37, 0.5, 0.62, 0.75, 0.87, 0.99]) # input y = array([10.6, 16.0, 45.0, 83.5, 52.8, 19.9, 10.8, 8.25, 4.7]) n = 9; np = 15 # Initialize y2 = zeros( (n), float); u = zeros( (n), float) graph1 = gdisplay(x=0,y=0,width=500, height=500, title='Spline Fit', xtitle='x', ytitle='y') funct1 = gdots(color = color.yellow) funct2 = gdots(color = color.red) graph1.visible = 0 def update(): # Nfit = 30 = output Nfit = int(control.value) for i in range(0, n): # Spread out points funct1.plot(pos = (x[i], y[i]) ) funct1.plot(pos = (1.01*x[i], 1.01*y[i]) ) funct1.plot(pos = (.99*x[i], .99*y[i]) ) yp1 = (y[1]-y[0]) / (x[1]-x[0]) - (y[2]-y[1])/ \ (x[2]-x[1])+(y[2]-y[0])/(x[2]-x[0]) ypn = (y[n-1] - y[n-2])/(x[n-1] - x[n-2]) - (y[n-2]-y[n-3])/(x[n-2]-x[n-3]) + (y[n-1]-y[n-3])/(x[n-1]-x[n-3]) if (yp1 > 0.99e30): y2[0] = 0.; u[0] = 0. else:
def plotTrajectory(arg, color = sf.cyan, xyRate=True, radiusRate = 80.0 , blAxes = True): """' plot 2D/3D trajectory. You can hand over list of length 2 element at 2D or length 3 element at 3D. The line radius is 1/200 for max display size. The line radius can be changed by radiusRate. If blAxes = False then the RGB axis is not displayed. At 2D plot, if xyRage == False then plot in a same hight/width square '""" if not(hasattr(arg, '__getitem__')) and hasattr(arg, '__iter__'): arg = list(arg) vs = sf.vs_() color = tuple(color) # color argment may be list/vector if isinstance(arg,list) or isinstance(arg,tuple) or isinstance( arg,type(sf.sc.array([0,]))): from octnOp import ClOctonion if not(hasattr(arg[0],'__len__')) and isinstance(arg[0], complex): arg = [ (x.real, x.imag) for x in arg] elif not(hasattr(arg[0],'__len__')) and isinstance(arg[0], ClOctonion): arg = [ x[1:4] for x in arg] if len(arg[0])==2: import visual.graph as vg global __obj2dDisplayGeneratedStt maxX = max([abs(elm[0]) for elm in arg]) maxY = max([abs(elm[1]) for elm in arg]) print "maxX:",maxX, " maxY:",maxY if (__obj2dDisplayGeneratedStt == None): if xyRate == True: # 11.01.16 to maxAt = max(maxX, maxY) __obj2dDisplayGeneratedStt = vg.gdisplay( width=600*maxX/maxAt,height=600*maxY/maxAt) else: __obj2dDisplayGeneratedStt = vg.gdisplay( width=600,height=600) #__bl2dDisplayGeneratedStt = True grphAt = vg.gcurve(color = color) for i in range(len(arg)): assert len(arg[i])==2, "unexpeted length data:"+str(arg[i]) grphAt.plot(pos = arg[i]) #return __obj2dDisplayGeneratedStt #import pdb; pdb.set_trace() #print "debug:",grphAt.gcurve.pos # plot start mark grphSqAt = vg.gcurve(color = color) pos0At = grphAt.gcurve.pos[0,:][:2] rateAt = 50 for x,y in sf.mitr([-maxX/rateAt, maxX/rateAt] , [-maxY/rateAt, maxY/rateAt]): grphSqAt.plot(pos = pos0At+[x,y]) grphSqAt.plot(pos = pos0At+[-maxX/rateAt,-maxY/rateAt]) return grphAt # 09.02.04 to animate graph elif len(arg[0])==3: vs.scene.forward=(-1,+1,-1) vs.scene.up=(0,0,1) c = vs.curve( color = color ) maxX, maxY, maxZ = 0,0,0 for i in range(len(arg)): if maxX < abs(arg[i][0]): maxX = abs(arg[i][0]) if maxY < abs(arg[i][1]): maxY = abs(arg[i][1]) if maxZ < abs(arg[i][2]): maxZ = abs(arg[i][2]) c.append( arg[i] ) #print c.pos print "maxX:",maxX, " maxY:",maxY, " maxZ:",maxZ maxAt = max(maxX,maxY,maxZ) c.radius = maxAt/radiusRate vs.sphere(pos = arg[0], radius = 3*c.radius, color = color) if blAxes == True: # draw axise vs.curve( pos=[(0,0,0), (maxAt,0,0)] , color=(1,0,0) , radius = maxAt/100 ) vs.curve( pos=[(0,0,0), (0,maxAt,0)] , color=(0,1,0) , radius = maxAt/100 ) vs.curve( pos=[(0,0,0), (0,0,maxAt)] , color=(0,1,1) , radius = maxAt/100 ) #return vs.scene return c # 09.02.04 to animate graph else: assert False,"unexpeted data:"+str(arg)
def plotGr(vctAg, start=(), end=None, N=50, color = sf.cyan): """' plot graph for a function or vector data If you call plotGr(..) a number of times, then the graphs were plotted in piles. start,end are domain parameters, which are used if vctAg type is function if you want to vanish the graph then do as below objAt=plotGr(..) . . objAt.visible = None usage: plotGr(sin) # plot sin graph in a range from 0 to 1 plotGr(sin,-3,3) #plot sin in a range from -3 to 3 plotGr(sin,[-3,-2,0,1]) # plot sequential line graph by # [(-3,sin(-3),(-2,sin(-2),(0,sin(0),(1,sin(1)] plotGr([sin(x) for x in klsp(-3,3)]) # plot a sequence data '""" if not(hasattr(vctAg, '__getitem__')) and hasattr(vctAg, '__iter__'): vctAg = list(vctAg) vs = sf.vs_() global __objGrDisplayGeneratedStt color = tuple(color) # color argment may be list/vector import visual.graph as vg if __objGrDisplayGeneratedStt == None: __objGrDisplayGeneratedStt = vg.gdisplay() grphAt = vg.gcurve( color = color) #grphAt = vg.gcurve(gdisplay=dspAt, color = color) #import pdb; pdb.set_trace() if '__call__' in dir(vctAg): # vctAg is function if start != () and end == None and hasattr(start, '__iter__'): for x in start: grphAt.plot(pos = [x, float(vctAg(x))] ) else: if start == (): start = 0 if end == None: end = 1 assert start != end if start > end: start, end = end, start #assert start != end """' for x in arsq(start, N, float(end-start)/N): # 08.10.27 add float(..) cast to avoid below error # "No registered converter was able to produce a C++ rvalue" # at ;;n=64;plotGr([sf.sc.comb(n,i) for i in range(n)]) grphAt.plot(pos = [x, float(vctAg(x))] ) '""" for x in sf.klsp(start, end, N): # 09.12.03 to display end and avoid 0 grphAt.plot(pos = [x, float(vctAg(x))] ) #return grphAt return __objGrDisplayGeneratedStt else: if (start != ()) or (end != None): #import pdb; pdb.set_trace() if start == (): start = 0 if end == None: end = 1 assert start != end if start > end: start, end = end, start N = len(vctAg) for i, x in enmasq([start, N, (end - start)/N]): grphAt.plot(pos = [x, float(vctAg[i])] ) else: for i in range(len(vctAg)): grphAt.plot(pos = [i, float(vctAg[i])] ) #return grphAt return __objGrDisplayGeneratedStt
#Efecto Talbot from visual import * from visual.graph import gdisplay, gdots m = 1. #cte. L = 1.e-3 #Frecuencia espacial de la red de difraccion en m D = 10.*L #Longitud de la red en m lamb = 520e-9 #Longitud de onda del verde en m dx = L/30. #Paso escena = gdisplay(height=500,width=500, xmin=-0.5*D,xmax=0.5*D,ymin=-0.5*D,ymax=0.5*D) puntos = [] def Intensidad(x,z): I = 0.25*(1.+2.*m*cos(pi*lamb*z/(L*L))*cos(2.*pi*x/L) +m*m*cos(2.*pi*x/L)**2) return I j=0 for i in arange(-0.5*D,0.5*D,dx): puntos.append(gdots()) puntos[j].radius=dx/2
height=0.005, width=plate_size, color=color.blue ) plate.velocity = vector(0, A*omega*cos(phi), 0) # Define balls balls = [ sphere(pos=(-plate_size/4, 0, 0), color=color.yellow), sphere(pos=( 0 , 0, 0), color=color.red ), sphere(pos=( plate_size/4, 0, 0), color=color.green ) ] for i in range(len(height)) : balls[i].pos.y = height[i]+plate.height balls[i].radius = ball_size/2.0 balls[i].id = str(i) # Tag ball for b in balls: b.velocity = vector(0,0,0) # Define y position plots position_plots = gdisplay(width=800, height=240, title='Vertical position of balls and plate vs time', xtitle='time', ytitle='y', y=400, foreground=color.black, background=(0.5,0.5,0.5)) plateplot = gcurve(gdisplay=position_plots, color=color.blue) for b in balls: b.y_plot = gcurve(gdisplay=position_plots, color=b.color) # Define bounce time plots step_plots = gdisplay(width=600, height=400, x=200, title='Current vs previous bounce intervals', xtitle='previous bounce', ytitle='current bounce (in units of plate oscillation period)', foreground=color.black, background=(0.5,0.5,0.5)) for b in balls: b.step_plot = gdots(gdisplay=step_plots, color=b.color) def bounce(ball,a,L): bounced = False # Calculate new ball velocity and position using symplectic Euler method.
def Simulation(): config.Atoms = [] # spheres p = [] # momentums (vectors) apos = [] # positions (vectors) ampl = 0 #амплитуда движения period = 5 k = 1.4E-23 # Boltzmann constant R = 8.3 dt = 1E-5 time = 0 def checkCollisions(Natoms, Ratom): hitlist = [] r2 = 2 * Ratom for i in range(Natoms): for j in range(i): dr = apos[i] - apos[j] if dr.mag < r2: hitlist.append([i, j]) return hitlist def speed(time, piston_mode, period, ampl, temp): if (piston_mode == 0): return 0 if (piston_mode == 1): return ampl / 10 * 3 * sin(time / period * 2 * pi) * sqrt( 3 * config.mass * k * temp) / (5 * config.mass) / period * 100 if (piston_mode == 2): if (time % period < period // 2): return 1.5 * ampl / 10 * sqrt(3 * config.mass * k * temp) / ( 5 * config.mass) / period * 100 else: return -1.5 * ampl / 10 * sqrt(3 * config.mass * k * temp) / ( 5 * config.mass) / period * 100 if (piston_mode == 3): if (time % period < period // 5): return 5 * ampl / 10 * sqrt(3 * config.mass * k * temp) / ( 5 * config.mass) / period * 100 else: return -5 / 4 * ampl / 10 * sqrt( 3 * config.mass * k * temp) / (5 * config.mass) / period * 100 if (piston_mode == 4): if (time % period < 4 * period // 5): return 5 / 4 * ampl / 10 * sqrt(3 * config.mass * k * temp) / ( 5 * config.mass) / period * 100 else: return -5 * ampl / 10 * sqrt(3 * config.mass * k * temp) / ( 5 * config.mass) / period * 100 width, height = config.w.win.GetSize() offset = config.w.dheight deltav = 100 # histogram bar width disp = display( window=config.w, x=offset, y=offset, forward=vector(0, -0.05, -1), range=1, # userspin = False, width=width / 3, height=height) g1 = gdisplay(window=config.w, x=width / 3 + 2 * offset, y=2 * offset, background=color.white, xtitle='t', ytitle='v', foreground=color.black, width=width / 3, height=height / 2 - 2 * offset) g2 = gdisplay(window=config.w, x=width / 3 + 2 * offset, y=height / 2 + offset, background=color.white, foreground=color.black, width=width / 3, height=height / 2 - 2 * offset) # adding empty dots to draw axis graph_average_speed = gcurve(gdisplay=g1, color=color.white) graph_average_speed.plot(pos=(3000, 1500)) graph_temp = gcurve(gdisplay=g2, color=color.white) graph_temp.plot(pos=(3000, config.Natoms * deltav / 1000)) speed_text = wx.StaticText(config.w.panel, pos=(width / 3 + 2 * offset, offset), label="Средняя скорость") graph_text = wx.StaticText(config.w.panel, pos=(width / 3 + 2 * offset, height / 2), label="") L = 1 # container is a cube L on a side d = L / 2 + config.Ratom # half of cylinder's height topborder = d gray = color.gray(0.7) # color of edges of container # cylinder drawing cylindertop = cylinder(pos=(0, d - 0.001, 0), axis=(0, 0.005, 0), radius=d) ringtop = ring(pos=(0, d, 0), axis=(0, -d, 0), radius=d, thickness=0.005) ringbottom = ring(pos=(0, -d, 0), axis=(0, -d, 0), radius=d, thickness=0.005) body = cylinder(pos=(0, -d, 0), axis=(0, 2 * d, 0), radius=d, opacity=0.2) # body_tmp = cylinder(pos = (0, d, 0), axis = (0, 2 * d, 0), radius = d + 0.1, color = (0, 0, 0)) # ceil = box(pos = (0, d, 0), length = 5, height = 0.005, width = 5, color = (0, 0, 0)) # floor = box(pos = (0, -d, 0), length = 100, height = 0.005, width = 100, color = (0, 0, 0)) # left = box(pos = (d + 0.005, 0, 0), axis = (0, 1, 0), length = 100, height = 0.005, width = 100, color = (0, 0, 0)) # right = box(pos = (-d - 0.005, 0, 0), axis = (0, 1, 0), length = 100, height = 0.005, width = 100, color = (0, 0, 0)) # uniform particle distribution for i in range(config.Natoms): qq = 2 * pi * random.random() x = sqrt(random.random()) * L * cos(qq) / 2 y = L * random.random() - L / 2 z = sqrt(random.random()) * L * sin(qq) / 2 if i == 0: # particle with a trace config.Atoms.append( sphere(pos=vector(x, y, z), radius=config.Ratom, color=color.cyan, make_trail=False, retain=100, trail_radius=0.3 * config.Ratom)) else: config.Atoms.append( sphere(pos=vector(x, y, z), radius=config.Ratom, color=gray)) apos.append(vector(x, y, z)) # waiting to start, adjusting everything according to changing variables """WAITING TO START""" last_Natoms = config.Natoms last_Ratom = config.Ratom while config.start == 0: if config.menu_switch == 0: disp.delete() g1.display.delete() g2.display.delete() graph_text.Destroy() speed_text.Destroy() return if config.Natoms > last_Natoms: for i in range(config.Natoms - last_Natoms): qq = 2 * pi * random.random() x = sqrt(random.random()) * L * cos(qq) / 2 y = L * random.random() - L / 2 z = sqrt(random.random()) * L * sin(qq) / 2 if last_Natoms == 0: # particle with a trace config.Atoms.append( sphere(pos=vector(x, y, z), radius=config.Ratom, color=color.cyan, make_trail=False, retain=100, trail_radius=0.3 * config.Ratom)) else: config.Atoms.append( sphere(pos=vector(x, y, z), radius=config.Ratom, color=gray)) apos.append(vector(x, y, z)) last_Natoms = config.Natoms elif config.Natoms < last_Natoms: for i in range(last_Natoms - config.Natoms): config.Atoms.pop().visible = False apos.pop() last_Natoms = config.Natoms if last_Ratom != config.Ratom: for i in range(last_Natoms): config.Atoms[i].radius = config.Ratom last_Ratom = config.Ratom if config.model == 0: if config.piston_mode >= 1: graph_text.SetLabel("Температура") else: graph_text.SetLabel("Распределение скоростей частиц") sleep(0.1) # freezed all variables, ready to start last_T = config.T last_ampl = config.ampl last_period = config.period last_piston_mode = config.piston_mode last_model = config.model pavg = sqrt(3 * config.mass * k * last_T) # average kinetic energy p**2/(2config.mass) = (3/2)kT for i in range(last_Natoms): theta = pi * random.random() phi = 2 * pi * random.random() px = pavg * sin(theta) * cos(phi) py = pavg * sin(theta) * sin(phi) pz = pavg * cos(theta) p.append(vector(px, py, pz)) if last_model == 1: disp.delete() unavail = wx.StaticText( config.w.panel, style=wx.ALIGN_CENTRE_HORIZONTAL, label="Отображение модели недоступно в режиме статистики", pos=(offset, height / 2 - offset)) unavail.Wrap(width / 3) last_period = last_period / 10 last_piston_mode += 1 graph_text.SetLabel("Температура") """ DRAW GRAPHS """ g1.display.delete() g2.display.delete() if last_piston_mode == 0: g1 = gdisplay(window=config.w, x=width / 3 + 2 * offset, y=2 * offset, background=color.white, xtitle='t', ytitle='v', foreground=color.black, width=width / 3, height=height / 2 - 2 * offset, ymin=0.7 * pavg / config.mass, ymax=1.3 * pavg / config.mass) g2 = gdisplay(window=config.w, x=width / 3 + 2 * offset, y=height / 2 + offset, background=color.white, foreground=color.black, xtitle='v', ytitle='Frequency', width=width / 3, height=height / 2 - 2 * offset, xmax=3000 / 300 * last_T, ymax=last_Natoms * deltav / 1000) else: g1 = gdisplay(window=config.w, x=width / 3 + 2 * offset, y=2 * offset, background=color.white, xtitle='t', ytitle='v', foreground=color.black, width=width / 3, height=height / 2 - 2 * offset) g2 = gdisplay(window=config.w, x=width / 3 + 2 * offset, y=height / 2 + offset, background=color.white, xtitle='t', ytitle='T', foreground=color.black, width=width / 3, height=height / 2 - 2 * offset) graph_average_speed = gcurve(gdisplay=g1, color=color.black) if last_piston_mode: graph_temp = gcurve(gdisplay=g2, color=color.black) else: theory_speed = gcurve(gdisplay=g2, color=color.black) dv = 10 for v in range(0, int(3000 / 300 * last_T), dv): theory_speed.plot(pos=(v, (deltav / dv) * last_Natoms * 4 * pi * ((config.mass / (2 * pi * k * last_T))**1.5) * exp(-0.5 * config.mass * (v**2) / (k * last_T)) * (v**2) * dv)) hist_speed = ghistogram(gdisplay=g2, bins=arange(0, int(3000 / 300 * last_T), 100), color=color.red, accumulate=True, average=True) speed_data = [] # histogram data for i in range(last_Natoms): speed_data.append(pavg / config.mass) # speed_data.append(0) """ MAIN CYCLE """ while config.start: while config.pause: sleep(0.1) rate(100) sp = speed(time, last_piston_mode, last_period, last_ampl, 300) cylindertop.pos.y -= sp * dt time += 1 for i in range(last_Natoms): config.Atoms[i].pos = apos[i] = apos[i] + (p[i] / config.mass) * dt if last_piston_mode == 0: speed_data[i] = mag(p[i]) / config.mass total_momentum = 0 v_sum = 0 for i in range(last_Natoms): total_momentum += mag2(p[i]) v_sum += sqrt(mag2(p[i])) / config.mass graph_average_speed.plot(pos=(time, v_sum / last_Natoms)) if last_piston_mode: graph_temp.plot(pos=(time, total_momentum / (3 * k * config.mass) / last_Natoms)) else: hist_speed.plot(data=speed_data) hitlist = checkCollisions(last_Natoms, last_Ratom) for ij in hitlist: i = ij[0] j = ij[1] ptot = p[i] + p[j] posi = apos[i] posj = apos[j] vi = p[i] / config.mass vj = p[j] / config.mass vrel = vj - vi a = vrel.mag2 if a == 0: # exactly same velocities continue rrel = posi - posj if rrel.mag > config.Ratom: # one atom went all the way through another continue # theta is the angle between vrel and rrel: dx = dot(rrel, norm(vrel)) # rrel.mag*cos(theta) dy = cross(rrel, norm(vrel)).mag # rrel.mag*sin(theta) # alpha is the angle of the triangle composed of rrel, path of atom j, and a line # from the center of atom i to the center of atom j where atome j hits atom i: alpha = asin(dy / (2 * config.Ratom)) d = (2 * config.Ratom) * cos( alpha ) - dx # distance traveled into the atom from first contact deltat = d / vrel.mag # time spent moving from first contact to position inside atom posi = posi - vi * deltat # back up to contact configuration posj = posj - vj * deltat mtot = 2 * config.mass pcmi = p[ i] - ptot * config.mass / mtot # transform momenta to cm frame pcmj = p[j] - ptot * config.mass / mtot rrel = norm(rrel) pcmi = pcmi - 2 * pcmi.dot(rrel) * rrel # bounce in cm frame pcmj = pcmj - 2 * pcmj.dot(rrel) * rrel p[i] = pcmi + ptot * config.mass / mtot # transform momenta back to lab frame p[j] = pcmj + ptot * config.mass / mtot apos[i] = posi + ( p[i] / config.mass) * deltat # move forward deltat in time apos[j] = posj + (p[j] / config.mass) * deltat # collisions with walls for i in range(last_Natoms): # проекция радиус-вектора на плоскость loc = vector(apos[i]) loc.y = 0 # вылет за боковую стенку (цилиндр радиуса L / 2 + config.Ratom) if (mag(loc) > L / 2 + 0.01 - last_Ratom + sqrt(p[i].x**2 + p[i].z**2) / config.mass * dt): # проекция импульса на плоскость proj_p = vector(p[i]) proj_p.y = 0 loc = norm(loc) # скалярное произведение нормированного радиус-вектора на импульс (все в проекции на плоскость) dotlp = dot(loc, proj_p) if dotlp > 0: p[i] -= 2 * dotlp * loc # dotlp < 0 - атом улетает от стенки # dotlp = 0 - атом летит вдоль стенки loc = apos[i] # вылет за торцы if loc.y + p[i].y / config.mass * dt < -L / 2 - 0.01 + last_Ratom: p[i].y = abs(p[i].y) if loc.y + p[ i].y / config.mass * dt > cylindertop.pos.y - last_Ratom: v_otn = p[i].y / config.mass + sp if v_otn > 0: p[i].y = (-v_otn - sp) * config.mass # type here if last_model == 0: disp.delete() else: unavail.Destroy() g1.display.delete() g2.display.delete() graph_text.Destroy() speed_text.Destroy()
def graphtool(self,count): self.ssidlabel=[] self.ssidcolor=[] self.f=vg.gdisplay(title='AterOS PyWifi-Analyzer==========Signal Quality',xmin=(-1.0*count/4),xmax=count,ymin=0.0,ymax=1.0,xtitle='count',ytitle='quality ratio') self.g=vg.gdisplay(title='AterOS PyWifi-Analyzer==========Signal Level',xmin=(-1.0*count/4),xmax=count,ymin=-100.0,ymax=0.0,xtitle='count',ytitle='level dbm')