Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- #include <vector>
- #include <time.h>
- #include <stdlib.h>
- #include <math.h>
- using namespace std;
- #define uint unsigned int
- struct Position {double x;
- double y;
- double z;};
- void random_walk(uint anzahl_schritte)
- {
- //Erstellen des Vektors mit den Positionen
- vector<Position> (anzahl_schritte+1);
- // vector<double> position_x(anzahl_schritte+1),
- // position_y(anzahl_schritte+1),
- // position_z(anzahl_schritte+1);
- //Startpunkt
- // position_x.at(0)=0;
- // position_y.at(0)=0;
- // position_z.at(0)=0;
- //Um Einheitslänge zu erhalten wechsel in Kugelkoordinaten
- double phi=0, theta=0;
- //Varianz
- // double varianz=0;
- for (uint i=1; i-1<anzahl_schritte; ++i)
- {
- phi = (double)(rand() % 36000)/100.;
- theta = (double)(rand() % 36000)/100.;
- //vergesse nicht, dass es sich immer um
- //eine neue Position in x, y, und z handelt
- //nach jedem Schritt!!
- //Rücktransformation in kartesische Koordianten und Speicherung in Vektor
- position_x.at(i) = position_x.at(i-1) + (cos(phi/180 * M_PI)) * (cos(theta/180 * M_PI));
- position_y.at(i) = position_y.at(i-1) + (sin(phi/180 * M_PI)) * (cos(theta/180 * M_PI));
- position_z.at(i) = position_z.at(i-1) + sin(theta/180 * M_PI);
- }
- cout << position_x.back() << " , " << position_y.back() << " , " << position_z.back() << endl;
- }
- int main()
- {
- //initialisiere random seed
- srand (time(NULL) );
- //Eingabe der Schrittzahl
- uint anzahl_schritte=0;
- cout << "Anzahl der Schritt: ";
- cin >> anzahl_schritte;
- random_walk(anzahl_schritte);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement