Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. c23456789012345678901234567890123456789012345678901234567890123456789012
  2. c        1         2         3         4         5         6         7
  3.  
  4.       subroutine sleep2
  5.         implicit none
  6.         integer i, j
  7.         do i=1, 10000
  8.           j = j + 1  
  9.         enddo
  10.       end subroutine
  11.  
  12.       double precision function norma(x, y)
  13.         implicit none
  14.         double precision x, y
  15.         norma = sqrt(x*x + y*y)
  16.         return
  17.       end function
  18.      
  19. c     (Ax, Ay) - (Bx, By) - pierwszy odcinek
  20. c     (Cx, Cy) - (Dx, Dy) - drugi odcinek
  21. c     (Ox, Oy) - punkt przecięcia
  22. c     Zwracana wartość: .true. - nastąpiło przecięcie, .false. - nie
  23.       logical function przeciecie_odcinkow(Ax, Ay, Bx, By, Cx, Cy,
  24.      +Dx, Dy, Ox, Oy)
  25.        implicit none
  26.        double precision Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Ox, Oy
  27.        double precision BAx, Bay, DCx, DCy, a, b, c, d, e, f
  28.        double precision W, eps, x, y
  29.        parameter (eps=1e-15)
  30.        BAx = Bx - Ax
  31.        BAy = By - Ay
  32.        DCx = Dx - Cx
  33.        DCy = Dy - Cy
  34. c układ równań:
  35. c   ax + by = c
  36. c   dx + ey = f
  37.        a = BAy
  38.        b = -BAx
  39.        c = DCy
  40.        d = -DCx
  41.        e = a*Ax + b*Ay
  42.        f = d*Cx + e*Cy
  43.        W = a*e - b*d
  44.        if (W.lt.eps) then
  45.          przeciecie_odcinkow = .false.
  46.          return
  47.        endif
  48.       x = (c*e - b*f) / W
  49.       y = (a*f - c*d) / W
  50. c a = rzut (x, y) na wektor BA
  51. c b = rzut (x, y) na wektor DC
  52. c jeżeli (x, y) na odcinku BA, to 0 <= a <= 1, podobnie dla DC
  53.       a = BAx*x + BAy*y
  54.       b = DCx*x + DCy*y
  55.       if (a.lt.0.or.a.gt.1.or.b.lt.0.or.b.gt.1) then
  56.         przeciecie_odcinkow = .false.
  57.         return
  58.       endif
  59.       przeciecie_odcinkow = .true.
  60.       Ox = x
  61.       Oy = y
  62.       return
  63.       end function
  64.        
  65.       subroutine zastosuj_brzegi(i)
  66.         implicit none
  67.         double precision p(0:1), p_nowe(0:1), v(0:1), O(0:1)
  68.         double precision banda(0:2, 0:1), norm(0:2, 0:1), ee, tmp
  69.         common p, p_nowe, v, banda, norm, ee
  70.         integer i, i2
  71.         logical trafiony, przeciecie_odcinkow
  72.        
  73.         if (i.lt.2) then
  74.           i2 = i + 1
  75.         else
  76.           i2 = 0
  77.         endif
  78.         trafiony = przeciecie_odcinkow(banda(i, 0), banda(i, 1),
  79.      +  banda(i2, 0), banda(i2, 1), p(0), p(1), p_nowe(0), p_nowe(1),
  80.      +  O(0), O(1))
  81.         if (trafiony) then
  82. c zatrzymaj punkt na punkcie zderzenia
  83.           p_nowe(0) = O(0)
  84.           p_nowe(1) = O(1)
  85. c zmień skłądową prostopadłą prędkości
  86.           tmp = v(0)*norm(i, 0) + v(1)*norm(i, 1)
  87.           v(0) = v(0) - ee*tmp*norm(i, 0)
  88.           v(1) = v(1) - ee*tmp*norm(i, 1)
  89.         endif
  90.       end subroutine
  91.      
  92.      
  93.       program bilard
  94.         implicit none
  95.         double precision p(0:1), p_nowe(0:1), v(0:1), banda(0:2, 0:1)
  96.         double precision norm(0:2, 0:1), min_v, dt, t, e, tmp, ee
  97.         double precision norma
  98.         integer i
  99.         parameter (min_v = 0.1)
  100.         parameter (dt = 0.01)
  101.         common p, p_nowe, v, banda, norm, ee
  102.        
  103.         e = 0
  104.         ee = e + 1.0
  105.        
  106.         p(0) = 0.0
  107.         p(1) = 0.0
  108.        
  109.         v(0) = 3.0
  110.         v(1) = 0.0
  111.        
  112.         banda(0, 0) = 0.0
  113.         banda(0, 1) = 3.0
  114.         banda(1, 0) = -2.0
  115.         banda(1, 1) = -1.0
  116.         banda(2, 0) = 2.0
  117.         banda(2, 1) = -1.0
  118.        
  119.        
  120.         norm(0, 0) = banda(0, 1) - banda(1, 1)
  121.         norm(0, 1) = banda(1, 0) - banda(0, 0)
  122.         tmp = norma(norm(0, 0), norm(0, 1))
  123.         norm(0, 0) = norm(0, 0) / tmp
  124.         norm(0, 1) = norm(0, 1) / tmp
  125.         norm(1, 0) = banda(1, 1) - banda(2, 1)
  126.         norm(1, 1) = banda(2, 0) - banda(1, 0)
  127.         tmp = norma(norm(1, 0), norm(1, 1))
  128.         norm(1, 0) = norm(1, 0) / tmp
  129.         norm(1, 1) = norm(1, 1) / tmp
  130.         norm(2, 0) = banda(2, 1) - banda(0, 1)
  131.         norm(2, 1) = banda(0, 0) - banda(2, 0)
  132.         tmp = norma(norm(2, 0), norm(2, 1))
  133.         norm(2, 0) = norm(2, 0) / tmp
  134.         norm(2, 1) = norm(2, 1) / tmp
  135.                
  136.         t = 0.0
  137.         print *, "czas polozenie_x polozenie_y predkosc"
  138.         do
  139.           p_nowe(0) = p(0) + v(0)*dt
  140.           p_nowe(1) = p(1) + v(1)*dt
  141.           do i=1,3
  142.             call zastosuj_brzegi(i)
  143.           enddo
  144.           p(0) = p_nowe(0)
  145.           p(1) = p_nowe(1)
  146.           tmp = norma(v(0), v(1))
  147.           print *, t, p(0), p(1), tmp
  148.           if( min_v.gt.tmp ) exit
  149.           t = t + dt
  150. c          call sleep(1)
  151.         enddo
  152.       end program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement