Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Kappaleen kitkallinen pitkin ympyrää x²+y² = R²
- # huipusta (0,0) irtoamiskohtaan
- # simulointi eulerin 1-kertaluvun menetelmällä
- # Juhani Kaukoranta 30.9.2022
- import pygame, math, time
- pygame.font.init()
- font = pygame.font.Font('freesansbold.ttf', 24)
- v0 = 0.5 # alkunopeus
- g = 9.80665 # putouskiihtyvyys
- r = 3 # kuulan säde pikseleinä
- R = 2 # ympyrän säde x,y-koordinaatistossa
- myy = 0.0 # kitkakerroin
- (x0,y0)=(0,R) # kpl lähtöpaikka ympyrän huipulta
- # 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("Kitkaton liike pitkin ellipsia x²/a²+y²/b²=1 tai siitä irroten")
- sk = 300 # skaalaus math coord to pygame coord koordinaatistoon
- origox = 200 # pygamen koordinaatiston origo
- origoy = 800
- text = font.render("ympyrä 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-100,origoy),(origox+700,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))
- time.sleep(5)
- for x1 in range (0,round(sk*(R)-5)): # puoliympyrän piirtäminen
- pygame.draw.circle(screen,magenta,(origox+x1,origoy - sk*(math.sqrt(R**2 - (x1/sk)**2))),1)
- pygame.time.delay(2)
- pygame.display.flip()
- (x,y) = (x0,y0) # kpl koordinaattien alkuarvo metreinä (lähpöpaikka)
- vx = v0 # vaakasuuntainen nopeuskomponentti
- vy = 0 # pystysuuntainen nopeuskomponentin itseisarvo
- v = v0 # alkunopeus
- Dt = 1/100.0 # aika-askel
- N = 1000 # N*Dt simuloinnin askelien maksimi
- time.sleep(5)
- done = False
- BLUE = (0, 0, 255) # sininen
- for j in range (0,N) : # simulointi alkaa
- pygame.draw.circle(screen, yellow,(origox+r+1+ sk*x,origoy-r-1 - sk*y),r) # kpl liukuu
- pygame.display.flip()
- pygame.time.delay(5) # kpl liukuu hidastetusti
- pygame.draw.circle(screen, black,(origox+r+1+ sk*x,origoy-r-1 - sk*y),r) # edellisen sammutus
- pygame.time.delay(5)
- tanphi = x/y # ympyrän tangentin tangenttikulman itseisarvo
- phi = math.atan(tanphi)
- cosphi = 1/math.sqrt(1+tanphi**2)
- sinphi = tanphi/math.sqrt(1+tanphi**2)
- # v = kappaleen ratanopeus
- v = math.sqrt(v0**2*math.exp(2*myy*phi)+g*R/(1+4*myy**2)*((math.exp(2*myy*phi)-cosphi)*(2-4*myy**2)-6*myy*sinphi))
- # kpl irtoaa ellipsistä jos v² > roo*cos(phi), joss phi=tangenttikulma
- if v**2 > R*g*cosphi:
- #kpl irtoaa ympyrästä, kun keskeisvoima on tukivoiman suuruinen
- v = int(100*v)/100
- kulma = int(100*phi*180/math.pi)/100 #irtoamiskulma
- text = font.render("v = "+str(v)+"m/s , kulma φ = "+str(kulma)+"°",True,yellow,black)
- screen.blit(text,(80,130))
- pygame.draw.line(screen, blue, (origox,origoy), (origox+r+1+ sk*x,origoy-r-1 - sk*y), 5)
- pygame.draw.circle(screen, yellow,(origox+r+1+ sk*x,origoy-r-1 - sk*y),r)
- text = font.render("φ",True,yellow,black)
- screen.blit(text,(origox+10,origoy-60))
- pygame.display.flip()
- break
- # kpl jatkaa liukumistaan
- vx = v*cosphi # nopeuden x-komponentti, vaaka vasempaan
- vy = v*sinphi # nopeuden y-komponentti, pysty alas
- x = x+ vx*Dt # kpl x-koordinaatti
- y = y - vy*Dt # kpl y-koordinaatti, kpl liukuu alas
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement