#include #include #include int range_rand(int i, int j);//rand(min,max) as in php int first_zero(float* arr);//find the first zero in an array. Maybe not necessary now? void gen_sins(float* sins, float* sins_vals);//generates some random numbers for the sinusoids. float f_x(float x2, float y1);//x position of the pen float f_y(float x2, float y1);//y position of the pen float c(float t, float tmax); //friction function float x(float t, float tmax, float* sinsx, float* sinsx_vals);//position of the oscillator float friction=1; int main(int argc, char* argv[]) { //argv[1] = x multi, argv[2] = y multi //argv[3] = tmax, argv[4] = t_increment long i,j; float t,tmax = 200,t_increment=0.02; float *x_pos; float *y_pos; //float x_pos[10000],y_pos[10000]; float xmax = -100,ymax = -100; float xmin = 100,ymin = 100; float xnormal, ynormal; float x_multi = 1,y_multi = 1; float sinsx[10*2],sinsy[10*2]; //10 sin cofactor, 10 t cofactor float sinsx_vals[2],sinsy_vals[2]; //normalization, length if(argc==6) { friction = atof(argv[5]); } if(argc>=5) { x_multi = atof(argv[1]); y_multi = atof(argv[2]); tmax = atof(argv[3]); t_increment = atof(argv[4]); x_pos = (float*)malloc((int)tmax/t_increment*sizeof(float)); y_pos = (float*)malloc((int)tmax/t_increment*sizeof(float)); } else { printf("This program outputs the points a pen connected by arms of some length to two perpendicular oscillators would trace out.\n\nUseage:\n%s x_max y_max max_runtime time_increment\n\nThe left/right columns vary between 0 and x_max/y_max.\n",argv[0]); return 0; } srand((unsigned) time(NULL)); gen_sins(sinsx, sinsx_vals); gen_sins(sinsy, sinsy_vals); i=0; for(t=0.1;t xmax) { xmax = x_pos[i]; } if(y_pos[i] > ymax) { ymax = y_pos[i]; } if(x_pos[i] < xmin) { xmin = x_pos[i]; } if(y_pos[i] < ymin) { ymin = y_pos[i]; } i++; } xnormal = xmax - xmin; ynormal = ymax - ymin; for(j=0;j1 || y_pos[j]>1 || x_pos[j]<0 || y_pos[j]<0) printf("FIX: %0.5f\t%0.5f\nORG: %0.5f\t%0.5f\nMIN: %0.5f\t%0.5f\nMAX: %0.5f\t%0.5f\nNRM: %0.5f\n\n", x_pos[j], y_pos[j], t, tmax, xmin, ymin, xmax, ymax, xnormal); */ } free(x_pos); free(y_pos); return 1; } int range_rand(int i, int j) { int k; k = i + rand() / ( RAND_MAX / ( j+1 - i ) + 1 ); return k; } int first_zero(float *arr) { int i=0; while(arr[i]>0) { i++; } return i; } void gen_sins(float *sins, float *sins_vals) { int i; int rand_i = 7;//range_rand(2,10); for(i=0; i<10; i++)/*Return array of premultiplier, internal multiplier.*/ { if(i