/ Published in: C
% gcc -lm rndwalk-torus.c
% ./a.out 1000 > rnd1.data
% gnuplot
gnuplot> splot "rnd1.data" with line
% ./a.out 1000 > rnd1.data
% gnuplot
gnuplot> splot "rnd1.data" with line
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> #define R (M_PI*4) #define r (M_PI*2) int main(int argc, char **argv) { int i, step; double x=R+r, y=0.0, z=0.0; double theta=0.0, phi=0.0, omega; } for(i=0; i<step; i++){ if(theta<0) theta+=M_PI*2; else if(theta>M_PI*2) theta-=M_PI*2; if(phi<0) phi+=M_PI*2; else if(phi>M_PI*2) phi-=M_PI*2; } return 0; }