Advertisement
stevn

Skrå kast padoru

Dec 5th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. g = 9.82
  2.  
  3. p0 = 0
  4.  
  5. posy = 0
  6.  
  7. posx = 0
  8.  
  9. rposy = 0
  10.  
  11. rposx = 0
  12.  
  13. vvekx = 0
  14.  
  15. vveky = 0
  16.  
  17. p0[1] = readline("x0")
  18.  
  19. p0[2] = readline("y0")
  20.  
  21. vinkel = readline("vinkel")
  22.  
  23. v0 = readline("kastehastighed")
  24.  
  25.  
  26. p0 = as.double(p0)
  27.  
  28. vinkel = as.double(vinkel)
  29.  
  30. v0 = as.double(v0)
  31.  
  32.  
  33. vinkel = pi/180*vinkel
  34.  
  35.  
  36. vx = cos(vinkel)
  37.  
  38. vy = sin(vinkel)
  39.  
  40.  
  41. thyme = seq(0, 200, 0.1)
  42.  
  43.  
  44. for(i in 1:length(thyme)){
  45. posy[i] = (p0[2]+vy*thyme[i]*v0-1/2*g*thyme[i]^2)
  46.  
  47. posx[i] = (p0[1]+vx*thyme[i]*v0)
  48.  
  49. vvekx[i] = vx*v0
  50.  
  51. vveky[i] = (vy*v0-g*thyme[i])
  52.  
  53.  
  54. }
  55.  
  56.  
  57. for(o in 1:1000){
  58.  
  59. if(posy[o] < 0){
  60.  
  61. break()
  62. }else{
  63.  
  64. rposx[o] = posx[o]
  65.  
  66. rposy[o] = posy[o]
  67.  
  68. }
  69.  
  70.  
  71.  
  72. }
  73.  
  74. cho = readline("1:animation, 2:graf")
  75.  
  76. if(cho =="2"){
  77.  
  78. for(r in 1:length(rposy)){
  79. plot(rposx,rposy,xlab="længde", ylab="højde", col="red")
  80.  
  81. arrows(rposx[r], rposy[r], rposx[r]+vvekx[r], vveky[r]+rposy[r], length = 0.5, col="green")
  82.  
  83. arrows(rposx[r]-2, rposy[r], rposx[r]+2, rposy[r], length = 0.001, col = "blue")
  84.  
  85. arrows(rposx[r], rposy[r]-2, rposx[r], 2+rposy[r], length = 0.001, col = "blue")
  86.  
  87. print(vveky[r])
  88.  
  89. Sys.sleep(0.5)
  90. }
  91.  
  92. }else{
  93.  
  94.  
  95. for(u in 1:length(rposy)){
  96.  
  97. anix = c(0, rposx[u], rposx[length(rposx)])
  98. aniy = c(0, rposy[u], 20)
  99. plot(anix,aniy,xlab="længde", ylab="højde", col="red")
  100. Sys.sleep(0.1)
  101. print("Padoru Padoru")
  102. }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement