Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <math.h>
- #include <iomanip>
- using namespace std;
- // For My Precious ВижакС++ 2012
- #define and &&
- #define or ||
- int main()
- {
- //freopen ("input.txt", "r", stdin);
- //freopen ("output.txt", "w", stdout);
- int n;
- cin >> n;
- cout << setprecision(6);
- double eps = 0.00000001;
- for (int i = 0; i < n; ++i){
- double x0, y0, r0, x1, y1, r1;
- double x2, y2, d;
- cin >> x0 >> y0 >> r0 >> x1 >> y1 >> r1;
- d = hypot(x1 - x0, y1 - y0);
- if (fabs(x0-x1)<eps and fabs(y0-y1)<eps and fabs(r0-r1)<eps){
- cout << "I can't count them - too many points :(" << endl;
- }
- else if (d + eps > r0 + r1 or fabs(x0 - x1)<eps and fabs(y0 - y1) and fabs(r0 - r1)>eps) {
- cout << "There are no points!!!" << endl;
- }
- else{
- x1 -= x0;
- y1 -= y0;
- double a = -2 * x1, b = -2 * y1, c = x1*x1 + y1*y1 + r0*r0 - r1*r1;
- c += a * x1 + b * y1;
- double ls = a * a + b * b;
- double _x0 = -a * c / ls;
- double _y0 = -b * c / ls;
- if (c * c > r1 * r1 * ls + eps) {
- cout << "There are no points!!!" << endl;
- }
- else if (fabsl(c * c - r1 * r1 * ls) < eps) {
- double _x1 = _x0 + x1 + x0;
- double _y1 = _y0 + y1 + y0;
- cout << "There are only 1 of them...." << endl;
- cout << _x1 << " " << _y1 << endl;
- }
- else {
- double d = r1 * r1 - c * c / ls;
- double m = sqrt(d / ls);
- double _x1 = _x0 + b * m + x1 + x0, _y1 = _y0 - a * m + y1 + y0;
- double _x2 = _x0 - b * m + x1 + x0, _y2 = _y0 + a * m + y1 + y0;
- if (_x1 > _x2 + eps) {
- swap(_x1, _x2);
- swap(_y1, _y2);
- }
- else if (fabs(_x1 - _x2) < eps) {
- if (_y1 > _y2 + eps) {
- swap(_x1, _x2);
- swap(_y1, _y2);
- }
- }
- cout << _x1 << " " << _y1 << endl;
- cout << _x2 << " " << _y2 << endl;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement