Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <math.h>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. // For My Precious ВижакС++ 2012
  8. #define and &&
  9. #define or ||
  10.  
  11. int main()
  12. {
  13.     //freopen ("input.txt", "r", stdin);
  14.     //freopen ("output.txt", "w", stdout);
  15.     int n;
  16.     cin >> n;
  17.     cout << setprecision(6);
  18.     double eps = 0.00000001;
  19.     for (int i = 0; i < n; ++i){
  20.         double x0, y0, r0, x1, y1, r1;
  21.         double x2, y2, d;
  22.         cin >> x0 >> y0 >> r0 >> x1 >> y1 >> r1;
  23.         d = hypot(x1 - x0, y1 - y0);
  24.         if (fabs(x0-x1)<eps and fabs(y0-y1)<eps and fabs(r0-r1)<eps){
  25.             cout << "I can't count them - too many points :(" << endl;
  26.         }
  27.         else if (d + eps > r0 + r1 or fabs(x0 - x1)<eps and fabs(y0 - y1) and fabs(r0 - r1)>eps) {
  28.             cout << "There are no points!!!" << endl;
  29.         }
  30.         else{
  31.             x1 -= x0;
  32.             y1 -= y0;
  33.  
  34.             double a = -2 * x1, b = -2 * y1, c = x1*x1 + y1*y1 + r0*r0 - r1*r1;
  35.             c += a * x1 + b * y1;
  36.  
  37.             double ls = a * a + b * b;
  38.  
  39.             double _x0 = -a * c / ls;
  40.             double _y0 = -b * c / ls;
  41.  
  42.             if (c * c > r1 * r1 * ls + eps) {
  43.                 cout << "There are no points!!!" << endl;
  44.             }
  45.             else if (fabsl(c * c - r1 * r1 * ls) < eps) {
  46.                 double _x1 = _x0 + x1 + x0;
  47.                 double _y1 = _y0 + y1 + y0;
  48.                 cout << "There are only 1 of them...." << endl;
  49.                 cout << _x1 << " " << _y1 << endl;
  50.             }
  51.             else {
  52.                 double d = r1 * r1 - c * c / ls;
  53.                 double m = sqrt(d / ls);
  54.  
  55.                 double _x1 = _x0 + b * m + x1 + x0, _y1 = _y0 - a * m + y1 + y0;
  56.                 double _x2 = _x0 - b * m + x1 + x0, _y2 = _y0 + a * m + y1 + y0;
  57.  
  58.                 if (_x1 > _x2 + eps) {
  59.                     swap(_x1, _x2);
  60.                     swap(_y1, _y2);
  61.                 }
  62.                 else if (fabs(_x1 - _x2) < eps) {
  63.                     if (_y1 > _y2 + eps) {
  64.                         swap(_x1, _x2);
  65.                         swap(_y1, _y2);
  66.                     }
  67.                 }
  68.                 cout << _x1 << " " << _y1 << endl;
  69.                 cout << _x2 << " " << _y2 << endl;
  70.             }
  71.         }
  72.     }
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement