Advertisement
jukaukor

Kitkallinen_ympyraliuku.py

Aug 30th, 2022 (edited)
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. # Kappaleen kitkallinen pitkin ympyrää x²+y² = R²
  2. # huipusta (0,0) irtoamiskohtaan
  3. # simulointi eulerin 1-kertaluvun menetelmällä
  4. # Juhani Kaukoranta 30.9.2022
  5. import pygame, math, time
  6. pygame.font.init()
  7. font = pygame.font.Font('freesansbold.ttf', 24)
  8. v0 = 0.5 # alkunopeus
  9. g = 9.80665 # putouskiihtyvyys
  10. r = 3 # kuulan säde pikseleinä
  11. R = 2 # ympyrän säde x,y-koordinaatistossa
  12. myy = 0.0 # kitkakerroin
  13. (x0,y0)=(0,R) # kpl lähtöpaikka ympyrän huipulta
  14. # piirtoalueen asetus
  15. (width,height) = (1000,1000) # näytön koko pikseleinä
  16. screen = pygame.display.set_mode((width, height))
  17. black = (0,0,0)
  18. yellow =(255,255,0)
  19. red = (255,0,0)
  20. blue = (0,0,255)
  21. magenta = (255,0,255)
  22. screen.fill(black)
  23. pygame.display.set_caption("Kitkaton liike pitkin ellipsia x²/a²+y²/b²=1 tai siitä irroten")
  24. sk = 300 # skaalaus math coord to pygame coord koordinaatistoon
  25. origox = 200 # pygamen koordinaatiston origo
  26. origoy = 800
  27. text = font.render("ympyrä x^2 + y^2 = "+str(R)+"^2",True,yellow,black)
  28. screen.blit(text,(80,40))
  29. text = font.render("Alkunopeus v0 = "+str(v0)+" m/s",True,yellow,black)
  30. screen.blit(text,(80,70))
  31. text = font.render("Jos v² > R*g*cosφ(), kpl irtoaa ympyrästä",True,yellow,black)
  32. screen.blit(text,(80,100))
  33. pygame.draw.line(screen,red,(origox-100,origoy),(origox+700,origoy),2) # x-akseli
  34. pygame.draw.line(screen,red,(origox,origoy),(origox,origoy-650),2) # y-akseli
  35. text = font.render("R = "+str(R)+" m",True,yellow,black)
  36. screen.blit(text,(origox+10,origoy-sk*R/2))
  37. time.sleep(5)
  38.  
  39. for x1 in range (0,round(sk*(R)-5)): # puoliympyrän piirtäminen
  40. pygame.draw.circle(screen,magenta,(origox+x1,origoy - sk*(math.sqrt(R**2 - (x1/sk)**2))),1)
  41. pygame.time.delay(2)
  42. pygame.display.flip()
  43. (x,y) = (x0,y0) # kpl koordinaattien alkuarvo metreinä (lähpöpaikka)
  44. vx = v0 # vaakasuuntainen nopeuskomponentti
  45. vy = 0 # pystysuuntainen nopeuskomponentin itseisarvo
  46. v = v0 # alkunopeus
  47. Dt = 1/100.0 # aika-askel
  48. N = 1000 # N*Dt simuloinnin askelien maksimi
  49. time.sleep(5)
  50. done = False
  51. BLUE = (0, 0, 255) # sininen
  52. for j in range (0,N) : # simulointi alkaa
  53. pygame.draw.circle(screen, yellow,(origox+r+1+ sk*x,origoy-r-1 - sk*y),r) # kpl liukuu
  54. pygame.display.flip()
  55. pygame.time.delay(5) # kpl liukuu hidastetusti
  56. pygame.draw.circle(screen, black,(origox+r+1+ sk*x,origoy-r-1 - sk*y),r) # edellisen sammutus
  57. pygame.time.delay(5)
  58. tanphi = x/y # ympyrän tangentin tangenttikulman itseisarvo
  59. phi = math.atan(tanphi)
  60. cosphi = 1/math.sqrt(1+tanphi**2)
  61. sinphi = tanphi/math.sqrt(1+tanphi**2)
  62. # v = kappaleen ratanopeus
  63. 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))
  64. # kpl irtoaa ellipsistä jos v² > roo*cos(phi), joss phi=tangenttikulma
  65. if v**2 > R*g*cosphi:
  66. #kpl irtoaa ympyrästä, kun keskeisvoima on tukivoiman suuruinen
  67. v = int(100*v)/100
  68. kulma = int(100*phi*180/math.pi)/100 #irtoamiskulma
  69. text = font.render("v = "+str(v)+"m/s , kulma φ = "+str(kulma)+"°",True,yellow,black)
  70. screen.blit(text,(80,130))
  71. pygame.draw.line(screen, blue, (origox,origoy), (origox+r+1+ sk*x,origoy-r-1 - sk*y), 5)
  72. pygame.draw.circle(screen, yellow,(origox+r+1+ sk*x,origoy-r-1 - sk*y),r)
  73. text = font.render("φ",True,yellow,black)
  74. screen.blit(text,(origox+10,origoy-60))
  75. pygame.display.flip()
  76. break
  77.  
  78. # kpl jatkaa liukumistaan
  79. vx = v*cosphi # nopeuden x-komponentti, vaaka vasempaan
  80. vy = v*sinphi # nopeuden y-komponentti, pysty alas
  81. x = x+ vx*Dt # kpl x-koordinaatti
  82. y = y - vy*Dt # kpl y-koordinaatti, kpl liukuu alas
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement