Advertisement
osipyonok

1510

Jun 2nd, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.17 KB | None | 0 0
  1. // nm
  2. #include <iostream>
  3. #include <vector>
  4. #include <cmath>
  5.  
  6. int kramer(double,double,double,double,double,double,double*,double*);
  7. void midperpend (double,double,double,double,double*,double*,double*);
  8. void circle(double x1, double y1, double x2, double y2, double x3, double y3, double *xc, double *yc, double *r);
  9. #define EPS 1e-6
  10.  
  11.  
  12. using namespace std;
  13.  
  14. int kramer(double a1,double b1, double c1,
  15.            double a2,double b2, double c2, double *x, double *y)
  16. {
  17.   double d = a1 * b2 - a2 * b1;
  18.   double dx = c1 * b2 - c2 * b1;
  19.   double dy = a1 * c2 - a2 * c1;
  20.   if (!d) return (dx == 0.0) + 1;
  21.   *x = dx/d; *y = dy/d;
  22.   return 0;
  23. }
  24.  
  25. void midperpend(double x1, double y1, double x2, double y2,
  26.                 double *a, double *b, double *c)
  27. {
  28.   *a = x2 - x1;
  29.   *b = y2 - y1;
  30.   *c = (x1*x1 - x2*x2 + y1*y1 - y2*y2) / 2;
  31. }
  32.  
  33. void circle(double x1, double y1, double x2, double y2, double x3, double y3,
  34.             double *xc, double *yc, double *r)
  35. {
  36.   double a1,b1,c1,a2,b2,c2;
  37.   midperpend(x1,y1,x2,y2,&a1,&b1,&c1);
  38.   midperpend(x1,y1,x3,y3,&a2,&b2,&c2);
  39.   kramer(a1,b1,-c1,a2,b2,-c2,xc,yc);
  40.   *r = sqrt((x1 - *xc)*(x1 - *xc) + (y1 - *yc)*(y1 - *yc));
  41. }
  42.  
  43. int main() {
  44.  double x_1,x_2,x_3,y_1,y_2,y_3,xc,rc,yc,r,r1;
  45. while(scanf("%lf %lf %lf %lf %lf %lf",&x_1,&y_1,&x_2,&y_2,&x_3,&y_3) == 6)
  46. {
  47.   circle(x_1,y_1,x_2,y_2,x_3,y_3,&xc,&yc,&r);
  48.   if (fabs(xc) < EPS) printf("x^2"); else
  49.   {
  50.     printf("(x");
  51.     if (xc >= 0.0) printf(" - "); else printf(" + ");
  52.     printf("%.3lf)^2",fabs(xc));
  53.   }
  54.   printf(" + ");
  55.   if (fabs(yc) < EPS) printf("y^2"); else
  56.   {
  57.     printf("(y",fabs(xc));
  58.     if (yc >= 0.0) printf(" - "); else printf(" + ");
  59.     printf("%.3lf)^2",fabs(yc));
  60.   }
  61.   printf(" = %.3lf^2\n",r);
  62.   printf("x^2 + y^2");
  63.  
  64.   if (fabs(xc) > EPS)
  65.   {
  66.     if (xc > 0.0) printf(" - "); else printf(" + ");
  67.     printf("%.3lfx",2*fabs(xc));
  68.    }
  69.   if (fabs(yc) > EPS)
  70.   {
  71.     if (yc > 0.0) printf(" - "); else printf(" + ");
  72.     printf("%.3lfy",2*fabs(yc));
  73.   }
  74.   r1 = xc*xc + yc*yc - r*r;
  75.   if (fabs(r1) > EPS)
  76.   {
  77.     if (r1 > 0.0) printf(" + "); else printf(" - ");
  78.     printf("%.3lf",fabs(r1));
  79.   }
  80.   printf(" = 0\n\n");
  81. }
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement