Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <vector>
  4. #include <time.h>
  5. #include <stdlib.h>
  6. #include <math.h>
  7. using namespace std;
  8. #define uint unsigned int
  9.  
  10. struct Position {double x;
  11.          double y;
  12.          double z;};
  13.  
  14. void random_walk(uint anzahl_schritte)
  15. {
  16.     //Erstellen des Vektors mit den Positionen
  17.     vector<Position> (anzahl_schritte+1);
  18.  
  19. //  vector<double> position_x(anzahl_schritte+1),
  20. //             position_y(anzahl_schritte+1),
  21. //             position_z(anzahl_schritte+1);
  22.    
  23.     //Startpunkt
  24.    
  25. //  position_x.at(0)=0;
  26. //  position_y.at(0)=0;
  27. //  position_z.at(0)=0;
  28.    
  29.     //Um Einheitslänge zu erhalten wechsel in Kugelkoordinaten
  30.     double phi=0, theta=0;
  31.    
  32.     //Varianz
  33. //  double varianz=0;
  34.    
  35.     for (uint i=1; i-1<anzahl_schritte; ++i)
  36.     {
  37.         phi = (double)(rand() % 36000)/100.;
  38.         theta = (double)(rand() % 36000)/100.;
  39.        
  40.         //vergesse nicht, dass es sich immer um
  41.         //eine neue Position in x, y, und z handelt
  42.         //nach jedem Schritt!!
  43.        
  44.         //Rücktransformation in kartesische Koordianten und Speicherung in Vektor
  45.         position_x.at(i) = position_x.at(i-1) + (cos(phi/180 * M_PI)) * (cos(theta/180 * M_PI));
  46.         position_y.at(i) = position_y.at(i-1) + (sin(phi/180 * M_PI)) * (cos(theta/180 * M_PI));
  47.         position_z.at(i) = position_z.at(i-1) + sin(theta/180 * M_PI);
  48.     }
  49.     cout << position_x.back() << " , " << position_y.back() << " , " << position_z.back() << endl;
  50. }
  51.  
  52. int main()
  53. {  
  54.     //initialisiere random seed
  55.     srand (time(NULL) );
  56.    
  57.     //Eingabe der Schrittzahl
  58.     uint anzahl_schritte=0;
  59.     cout << "Anzahl der Schritt: ";
  60.     cin >> anzahl_schritte;
  61.     random_walk(anzahl_schritte);  
  62.  
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement