pietrod21

casuale 3d con stampa

Dec 3rd, 2011
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4.  
  5. typedef unsigned long long int RANDOM_TYPE;
  6. RANDOM_TYPE a, b, m, seed, randomNumber;
  7.  
  8. struct{
  9. double x,y,z;
  10. }p;
  11.  
  12. int main(){
  13. double r, xt2, arraybin[10], distanzatot, media, bin=10000;
  14. int position, i, c,g,passi=10000;
  15. i=0; media=0;
  16. p.x=0; p.y=0; p.z=0;
  17. position=0;
  18. i=0;
  19. a=16807;
  20. m=2147483647;
  21. seed=222;
  22. randomNumber=seed;
  23. FILE *ff;
  24. FILE *fp;
  25. ff=fopen("casuale.dat","w+");
  26.     for(i=1; i<passi; i++){
  27.         randomNumber=(a*randomNumber)%m;
  28.         fprintf(ff,"%d %lf %lf %lf %Lu \n", i,p.x,p.y,p.z,randomNumber);
  29.         r=(double)randomNumber/(double)m;
  30.             if(r<(1/6.)){
  31.             p.z+=1;
  32.             }
  33.             else if (r<(2/6.)){
  34.             p.z-=1;
  35.             }
  36.             else if (r<(3/6.)){
  37.             p.x+=1;
  38.             }
  39.             else if (r<(4/6.)){
  40.             p.x-=1;
  41.             }
  42.             else if (r<(5/6.)){
  43.             p.y+=1;
  44.             }
  45.             else if (r<1){
  46.             p.y-=1;
  47.             }
  48.        
  49.     }
  50. fp=fopen("dati_png.gnu","w");
  51. fprintf(fp, " splot 'casuale.dat' u 2:3:4 \n set xlabel 'x' \n set ylabel 'y' \n set zlabel 'z'\n set term png \n set output 'casuale.png' \n replot \n  \n ");
  52. fclose(fp);
  53. system("gnuplot dati_png.gnu");
  54. fp=fopen("dati_ps.gnu","w");
  55. fprintf(fp, " plot 'casuale.dat' u 2:3:4 \n set xlabel 'x' \n set ylabel 'y' \n set zlabel 'z' \n set term post col \n set output 'eull.ps' \n replot \n  \n ");
  56. fclose(fp);
  57. system("gnuplot dati_ps.gnu");
  58. system("rm dati_ps.gnu");
  59. system("rm dati_png.gnu");
  60. system("gnuplot>splot 'casuale.dat' u 2:3:4");
  61. }
  62.  
  63.  
Advertisement
Add Comment
Please, Sign In to add comment