SHARE
TWEET

Untitled

a guest Aug 19th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (* Tracé d'une courbe *)
  2. #load "graphics.cma";;
  3. Graphics.open_graph "";;
  4. Graphics.moveto 30 30;;
  5.  
  6.  
  7. (* Point *)
  8. type point = {x:float; y:float};;
  9. let mk_point x1 y1 = {x=x1 ; y=y1};;
  10.  
  11.  
  12. (* Pixel *)
  13. type pixel = {xi:int; yi:int};;
  14. let mk_pixel x1 y1 = {xi=x1 ; yi=y1};;
  15.  
  16.  
  17. (* Fenetre *)
  18. type fenetre = {largeur:int; hauteur:int};;
  19. let mk_fenetre l h = {largeur=l ; hauteur=h};;
  20. (* Vérifier que les valeurs soient positives *)
  21.  
  22.  
  23. (* Echelle *)
  24. type echelle = {xmin:float; xmax:float; ymin:float; ymax:float};;
  25. let mk_echelle xmini xmaxi ymini ymaxi =
  26.     {xmin=xmini ; xmax=xmaxi ; ymin=ymini ; ymax=ymaxi};;
  27. (* Vérifier que xmax>xmin et ymax>ymin *)
  28.  
  29.    
  30. (* Fonction coords_vers_ecran *)
  31. let coords_vers_ecran pt ech fen =
  32.     mk_pixel (int_of_float (float_of_int (fen.largeur) *. (pt.x-.ech.xmin) /. (ech.xmax-.ech.xmin) ) ) (int_of_float (float_of_int (fen.hauteur) *. (pt.y-.ech.ymin) /. (ech.ymax-.ech.ymin) ) )
  33. ;;
  34.  
  35.  
  36. (* Fonction trace_segment *)
  37. let trace_segment p1 p2 =
  38.         Graphics.moveto p1.xi p1.yi;
  39.         Graphics.lineto p2.xi p2.yi
  40. ;;
  41.  
  42.  
  43. (* Fonction trace_lignes *)
  44. let rec trace_lignes lpix =
  45.     match lpix with
  46.     | [] -> ()
  47.     | _::[] -> ()
  48.     | h1::h2::t ->  trace_segment h1 h2 ;
  49.                     trace_lignes t
  50. ;;
  51.  
  52.  
  53. (* Liste de pixels *)
  54. let pix1 = mk_pixel 30 30;;
  55. let pix2 = mk_pixel 90 120;;
  56. let pix3 = mk_pixel 120 180;;
  57. let pix4 = mk_pixel 90 180;;
  58. let pix5 = mk_pixel 120 60;;
  59. let pix6 = mk_pixel 60 90;;
  60. let pix7 = mk_pixel 30 180;;
  61. let pix8 = mk_pixel 180 90;;
  62. let pix9 = mk_pixel 80 160;;
  63. let pix10 = mk_pixel 50 50;;
  64. let listpix = pix1::pix2::pix3::pix4::pix5::pix6::pix7::pix8::pix9::pix10::[];;
  65.  
  66.  
  67. (* Fonction f *)
  68. let f x = x*.x +. 2.*.x -. 3.
  69.  
  70. (* Fonction discr *)
  71. let rec discr f xmin xmax pas =
  72.     if xmin > xmax
  73.         then
  74.             []
  75.         else
  76.             (mk_point (xmin) (f xmin) ) :: discr f (xmin+.pas) xmax pas
  77. ;;
  78.  
  79.  
  80. (* Fonction discr_nb *)
  81. let discr_nb f xmin xmax nb =
  82.     discr f xmin xmax ((xmax -. xmin) /. nb)
  83. ;;
  84.  
  85.  
  86. (* Fonction lcoords_vers_ecran *)
  87. let rec lcoords_vers_ecran l ech fen =
  88.     match l with
  89.     | [] -> []
  90.     | h::t -> (coords_vers_ecran h ech fen) :: (lcoords_vers_ecran t ech fen)
  91. ;;
  92.  
  93.  
  94. (* Fonction courbe *)
  95. let courbe f ech fen nb =
  96.     lcoords_vers_ecran (discr_nb f ech.xmin ech.xmax nb) ech fen
  97. ;;
  98.  
  99.  
  100. (* Fonction trace_courbe *)
  101. let trace_courbe f ech fen nb =
  102.     trace_lignes (courbe f ech fen nb)
  103. ;;
  104.  
  105. (* Calcul de la dérivée en un point *)
  106. let df f x h = (f(x+.h) -. f(x-.h)) /. (2.*. h);;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top