www.pudn.com > 医学算法.rar > trace.c
#include#include /* trace - trace through single ellipse Carl Crawford Purdue University W. Lafayette, IN. 47907 Jan. 15, 1981 */ float a = 2.0; /* semi - major axis */ float b = 1.0; /* semi - minor axis */ float theta = 00.0; /* rotation of ellipse */ float tau = 1.8; /* transducer position */ float width = .3; /* width of transducer */ int dev = 3; /* plot device */ int print; /* 1=don't print program status */ float pi = 3.14159265;/* pi in the face */ int tang; /* 1 = draw tangent to center line */ float sc 1.0; /* scale factor */ char *table[] = { "a", "b", "theta", "tau", "width", "dev", 0 }; main(argc,argv) int argc; char **argv; { char c; float g,dg,cost,sint,x,y,at; float x1,y1,x2,y2,t1,t2; register int i; while(argv++ , --argc){ if(argv[0][0] == '-')while(c = *++*argv)switch(c){ case 'p': /* print flag */ print = 1; break; case 't': /* tangent */ tang = 1; break; case 'h': sc /= 2; break; default: fprintf(stderr,"bad flag: -%c\n",c); exit(1); } else switch(i = comm(*argv)){ case 1: a = atof(*argv + 2); break; case 2: b = atof(*argv + 2); break; case 3: theta = atof(*argv + 6); break; case 4: tau = atof(*argv + 4); break; case 5: width = atof(*argv + 6); break; case 6: dev = atoi(*argv + 4); break; } } if(!print){ printf("TRACE DATA\n\n"); printf("a = %f\n",a); printf("b = %f\n",b); printf("theta = %f\n",theta); printf("tau = %f\n",tau); printf("width = %f\n",width); } theta *= pi / 180.0; plots(dev,0); factor(sc); plot(5.0,5.0,-3); lplot(5.0,0.0,-5.0,0.0);/* draw axes */ lplot(0.0,5.0,0.0,-5.0); cost = cos(theta); sint = sin(theta); lplot(4.0*sint,4.0*cost,-4.0*sint,-4.0*cost); lplot(4.0*cost,-4.0*sint,-4.0*cost,4.0*sint); g = 0.0; /* draw ellipse */ dg = (pi + pi) / 199.0; for(i=0;i<200;i++){ x = a * cos(g); y = b * sin(g); plot(x*cost+y*sint,-x*sint+y*cost,2 + !i); g += dg; } lplot(-5.0,-4.0,5.0,-4.0); /* draw transducer axis */ lplot(tau,-4.0,tau,4.0); lplot(tau + width * 0.5,-4.0,tau + width * 0.5,4.0); lplot(tau - width * 0.5,-4.0,tau - width * 0.5,4.0); if(tang){ /* draw tangents */ at = a * a * cost * cost + b * b * sint * sint; if(at >= fabs(tau)){ t1 = a * a * tau * cost; t2 = a * b * sint * sqrt(at - tau * tau); x1 = (t1 - t2) / at; x2 = (t1 + t2) / at; y1 = b * sqrt(1- x1 * x1 / a / a); y2 = -b * sqrt(1- x2 * x2 / a / a); symbol(x1*cost+y1*sint,-x1*sint+y1*cost,.1,"x",0.0); symbol(x2*cost+y2*sint,-x2*sint+y2*cost,.1,"x",0.0); } } plot(0.0,0.0,999); } comm(s) char *s; { register int i,j,r; for(i=0;table[i];i++){ for(j=0;(r=table[i][j]) == s[j] && r;j++); if(r == 0 && s[j] == '=' && s[j+1] )return(i+1); } fprintf(stderr,"bad option: %s\n",s); exit(1); }