Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # vertical loop with friction
- # matematiikka artikkeliin Waldemar Klobus, Adam Mickiewicz University
- # Juhani Kaukoranta
- # 9.9.2022
- import pygame, time
- from math import sqrt,sin,cos,exp,pi
- pygame.font.init()
- font = pygame.font.Font('freesansbold.ttf', 24)
- v0 = 18.7 # alkunopeus m/s
- g = 9.80665 # putouskiihtyvyys
- r = 3 # kuulan säde pikseleinä
- R = 1.0 # ympyrän säde metreinä luonnossa
- myy = 0.5 # kitkakerroin
- (x0,y0)=(0,0) # kpl lähtöpaikka
- # piirtoalueen asetus
- (width,height) = (1000,1000) # näytön koko pikseleinä
- screen = pygame.display.set_mode((width, height))
- black = (0,0,0)
- yellow =(255,255,0)
- red = (255,0,0)
- blue = (0,0,255)
- magenta = (255,0,255)
- screen.fill(black)
- pygame.display.set_caption("vertical loop with friction")
- sk = 300 # skaalaus math coord to pygame coord koordinaatistoon
- origox = 500 # pygamen koordinaatiston origo
- origoy = 800
- text = font.render("vertical loop x^2 + y^2 = "+str(R)+"^2",True,yellow,black)
- screen.blit(text,(80,40))
- text = font.render("Alkunopeus v0 = "+str(v0)+" m/s",True,yellow,black)
- screen.blit(text,(80,70))
- #text = font.render("Jos v² > R*g*cosφ(), kpl irtoaa ympyrästä",True,yellow,black)
- #screen.blit(text,(80,100))
- pygame.draw.line(screen,red,(origox-400,origoy),(origox+400,origoy),2) # x-akseli
- #pygame.draw.line(screen,red,(origox,origoy),(origox,origoy-650),2) # y-akseli
- #text = font.render("R = "+str(R)+" m",True,yellow,black)
- #screen.blit(text,(origox+10,origoy-sk*R/2))
- pygame.draw.circle(screen,magenta,(origox,origoy-300),sk*R,width=1) # rata
- pygame.display.flip()
- (x,y) = (x0,y0) # kpl koordinaattien alkuarvo metreinä luonnossa (lähtöpaikka)
- phi = 0.0 # alkusuunta ympyrässä alas, kiertosuunta oikealle
- v = v0 # alkunopeus
- Dt = 1/100.0 # aika-askel
- N = 1000 # N*Dt simuloinnin askelien maksimi
- done = False
- lippu = ""
- BLUE = (0, 0, 255) # sininen
- text1 = font.render("kpl pysähtyy radalla",True,yellow,black)
- text2 = font.render("Putoaa ympyräradalta, tukivoima = 0, alkunopeus ei riitä",True,yellow,black)
- time.sleep(3)
- for j in range (0,N) : # simulointi alkaa
- v2 = g*R*exp(-2*myy*phi)*(v0**2/(g*R)+(4*myy**2-2)/(4*myy**2+1))-2*g*R/(4*myy**2+1)*((2*myy**2-1)*cos(phi)+3*myy*sin(phi))
- v = sqrt(v2) # kitkallinen nopeus
- if phi >= pi/2 and phi <= pi: # putoamisvaaran alue ennen huippua
- if v**2 <= g*R*sin(phi - pi/2): # putoaa ympyrästä keskeisvoiman takia
- lippu = "putoaa radalta keskeisvoiman takia"
- screen.blit(text2,(80,130))
- break
- # functio joka hoitelee vapaan putaomisen
- x = R*sin(phi) # kpl x-koordinaattit metreinä luonnossa
- y = R - R*cos(phi) # kpl y-koordinaatti metreinä luonnoss
- pygame.draw.circle(screen, yellow,(origox+r+2+ sk*x,origoy-r-2 +sk*R - sk*(y)-300),r) # kpl liukuu
- pygame.display.flip()
- pygame.time.delay(10) # kpl liukuu hidastetusti
- pygame.draw.circle(screen, black,(origox+r+2+ sk*x,origoy-r-2+sk*R-sk*(y)-300),r) # edellisen sammutus
- pygame.time.delay(10)
- dphi = v/R * Dt # kulman lisäys
- phi = phi + dphi # uusi kulma
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement