/**************************************************** * This program allows calculating the 4 parameters * * of an arc of circle knowing two of them. * * R:radius of circle S:curvilinear abscissa of arc * * C:length of chord T:angle of arc of circle (rad)* * ------------------------------------------------- * * Ref.: "Mathématiques en Turbo-Pascal By M. Ducamp * * and A. Reverchon (vol 2), Eyrolles, Paris, 1988" * * [BIBLI 05]. * * ------------------------------------------------- * * SAMPLE RUN: * * * * R=0 * * S=0 * * C=2 * * T=1 * * * * SUCCESS: YES. * * * * Radius : 2.0858296429 * * Curvilinear abscissa: 2.0858296429 * * Chord : 2.0000000000 * * Angle (radians) : 1.0000000000 * * * * Surface of angular sector : 2.1753426497 * * Surface between arc and chord : 0.3448549280 * * * * C++ Version By J-P Moreau. * * (www.jpmoreau.fr) * ****************************************************/ #include #include #define FALSE 0 #define TRUE 1 #define PI 3.14159265359 // LABEL fin double c,r,s,t,s1,s2; double a,b,u,x,y; int ndata; bool done; void main() { printf("\n ARC OF CIRCLE\n"); printf(" -----------------------------------------\n"); printf(" Give two parameters between:\n"); printf(" R: radius of circle\n"); printf(" S: curvilinear abscissa\n"); printf(" C: chord\n"); printf(" T: angle of arc in radians\n"); printf(" The other two must be given as zero.\n"); printf(" The program then calculates the\n"); printf(" missing parameters and the two surfaces:\n"); printf(" S1: total surface of angular sector\n"); printf(" S2: surface between chord and arc s.\n"); printf(" -----------------------------------------\n"); printf(" R= "); scanf("%lf",&r); printf(" S= "); scanf("%lf",&s); printf(" C= "); scanf("%lf",&c); printf(" T= "); scanf("%lf",&t); printf("\n");; done=FALSE; ndata=0; // verify consistency of data r,s,c,t if (r!=0) ndata++; if (s!=0) ndata++; if (c!=0) ndata++; if (t!=0) ndata++; if (ndata!=2) { printf(" Too many data != 0 (maximum two).\n"); goto fin; } if (t<0 || t>PI) { printf(" Angle t(radians) must be between 0 && PI.\n"); goto fin; } if (s>0 && c>=s) { printf(" Chord c must be smaller than curvilinear abscissa s.\n"); goto fin; } if (c>0 && s>c*PI/2) { printf(" Curvilinear abscissa s must be smaller than chord times PI/2.\n"); goto fin; } if (r>0 && s>PI*r) { printf(" Curvilinear abscissa s must be smaller then radius r times PI.\n"); goto fin; } //end of verify data if (t>0) if (r>0) { //---------------------- t && r are given ---- s=r*t; c=2*r*sin(t/2); } else if (s>0) { //---------------------- t && s are given ---- r=s/t; c=2*r*sin(t/2); } else { //---------------------- t && c are given ---- r=c/2/sin(t/2); s=r*t; } else // t is not given if (c==0) { //---------------------- r && s are given ---- t=s/r; c=2*r*sin(t/2); } else if (r>0) { //---------------------- r && c are given ---- if (c<2*r) t=2*atan(c/sqrt(4*r*r-c*c)); else t=PI; s=r*t; } else { //---------------------- s && c are given y=c; do { x=y; u=s/x; a=s*cos(u); b=x*sin(u)-a; if ((c-a)*b<=0) goto fin; y=x*(c-a)/b; } while (fabs(x-y)>1e-8); r=y/2; t=s/r; } // calculate surfaces s1 && s2 s1=s*r/2; s2=(s-c*cos(t/2))*r/2; done=TRUE; // print results if (done) { printf("\n SUCCESS: YES.\n\n"); printf(" Radius : %15.10f\n", r); printf(" Curvilinear abscissa: %15.10f\n", s); printf(" Chord : %15.10f\n", c); printf(" Angle (radians) : %15.10f\n", t); printf("\n"); printf(" Sector surface : %15.10f\n", s1); printf(" Surface between arc and chord : %15.10f\n\n", s2); } else printf("\n SUCCESS: NO.\n\n"); fin: printf("\n"); } // end of file arcircle.cpp