Advertisement
jukaukor

VerticalLoopWithFriction.py

Sep 9th, 2022 (edited)
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. # vertical loop with friction
  2. # matematiikka artikkeliin Waldemar Klobus, Adam Mickiewicz University
  3. # Juhani Kaukoranta
  4. # 9.9.2022
  5. import pygame, time
  6. from math import sqrt,sin,cos,exp,pi
  7. pygame.font.init()
  8. font = pygame.font.Font('freesansbold.ttf', 24)
  9. v0 = 18.7 # alkunopeus m/s
  10. g = 9.80665 # putouskiihtyvyys
  11. r = 3 # kuulan säde pikseleinä
  12. R = 1.0 # ympyrän säde metreinä luonnossa
  13. myy = 0.5 # kitkakerroin
  14. (x0,y0)=(0,0) # kpl lähtöpaikka
  15. # piirtoalueen asetus
  16. (width,height) = (1000,1000) # näytön koko pikseleinä
  17. screen = pygame.display.set_mode((width, height))
  18. black = (0,0,0)
  19. yellow =(255,255,0)
  20. red = (255,0,0)
  21. blue = (0,0,255)
  22. magenta = (255,0,255)
  23. screen.fill(black)
  24. pygame.display.set_caption("vertical loop with friction")
  25. sk = 300 # skaalaus math coord to pygame coord koordinaatistoon
  26. origox = 500 # pygamen koordinaatiston origo
  27. origoy = 800
  28. text = font.render("vertical loop x^2 + y^2 = "+str(R)+"^2",True,yellow,black)
  29. screen.blit(text,(80,40))
  30. text = font.render("Alkunopeus v0 = "+str(v0)+" m/s",True,yellow,black)
  31. screen.blit(text,(80,70))
  32. #text = font.render("Jos v² > R*g*cosφ(), kpl irtoaa ympyrästä",True,yellow,black)
  33. #screen.blit(text,(80,100))
  34. pygame.draw.line(screen,red,(origox-400,origoy),(origox+400,origoy),2) # x-akseli
  35. #pygame.draw.line(screen,red,(origox,origoy),(origox,origoy-650),2) # y-akseli
  36. #text = font.render("R = "+str(R)+" m",True,yellow,black)
  37. #screen.blit(text,(origox+10,origoy-sk*R/2))
  38.  
  39. pygame.draw.circle(screen,magenta,(origox,origoy-300),sk*R,width=1) # rata
  40. pygame.display.flip()
  41. (x,y) = (x0,y0) # kpl koordinaattien alkuarvo metreinä luonnossa (lähtöpaikka)
  42. phi = 0.0 # alkusuunta ympyrässä alas, kiertosuunta oikealle
  43. v = v0 # alkunopeus
  44. Dt = 1/100.0 # aika-askel
  45. N = 1000 # N*Dt simuloinnin askelien maksimi
  46. done = False
  47. lippu = ""
  48. BLUE = (0, 0, 255) # sininen
  49. text1 = font.render("kpl pysähtyy radalla",True,yellow,black)
  50. text2 = font.render("Putoaa ympyräradalta, tukivoima = 0, alkunopeus ei riitä",True,yellow,black)
  51. time.sleep(3)
  52. for j in range (0,N) : # simulointi alkaa
  53. 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))
  54. v = sqrt(v2) # kitkallinen nopeus
  55. if phi >= pi/2 and phi <= pi: # putoamisvaaran alue ennen huippua
  56. if v**2 <= g*R*sin(phi - pi/2): # putoaa ympyrästä keskeisvoiman takia
  57. lippu = "putoaa radalta keskeisvoiman takia"
  58. screen.blit(text2,(80,130))
  59. break
  60.  
  61. # functio joka hoitelee vapaan putaomisen
  62.  
  63. x = R*sin(phi) # kpl x-koordinaattit metreinä luonnossa
  64. y = R - R*cos(phi) # kpl y-koordinaatti metreinä luonnoss
  65. pygame.draw.circle(screen, yellow,(origox+r+2+ sk*x,origoy-r-2 +sk*R - sk*(y)-300),r) # kpl liukuu
  66. pygame.display.flip()
  67. pygame.time.delay(10) # kpl liukuu hidastetusti
  68. pygame.draw.circle(screen, black,(origox+r+2+ sk*x,origoy-r-2+sk*R-sk*(y)-300),r) # edellisen sammutus
  69. pygame.time.delay(10)
  70. dphi = v/R * Dt # kulman lisäys
  71. phi = phi + dphi # uusi kulma
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement