Given two circles on the same plane which are centered at (x1,y1) and (x2,y2) ,with radiuses r1 and r2, respectively.We can see that they have two common tangent lines in most of the cases.Now you are asked to write a programme to calculate the point of intersection of the two tangents if there exists one. ( See Figure 1 )
Figure. 1 Point of intersection
Input
The input data consists of the information of several figures.The first line of the input contains the number of figures.
Each figure is described by two lines of data.Each line contains 3 integers constituting the coordinates of the center (x, y) and the radius r (>0) of a circle.
Output
For each figure, you are supposed to output the coordinates (x, y) of the point of intersection if it exists.The x and y must be rounded to two decimal places and be separated by one space.If there is no such point exists simply output "Impossible."
Sample Input
2 0 0 10 0 0 5 0 0 10 10 0 1
Output for the Sample Input
Impossible. 11.11 0.00
Notice
The common tangent lines like the following figure don't take into account;
无聊的几何题,推公式就行了。
#include<map>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<math.h>
using namespace std;
long long a1,a2,b1,b2,r1,r2;
int main()
{
int _;
scanf("%d",&_);
while(_--)
{
scanf("%lld%lld%lld",&a1,&b1,&r1);
scanf("%lld%lld%lld",&a2,&b2,&r2);
if(r1==r2||(r1-r2)*(r1-r2)>=(a1-a2)*(a1-a2)+(b1-b2)*(b1-b2)) puts("Impossible.");
else
{
if(r1<r2)
{
swap(a1,a2);
swap(b1,b2);
swap(r1,r2);
}
double d1=(a1-a2)*(a1-a2)+(b1-b2)*(b1-b2);
d1=sqrt(d1);
double d=d1*r2/(r1-r2);
double k1=1.0*(b2-b1);
double k2=1.0*(a2-a1);
printf("%.2lf %.2lf\n",a2+d*k2/sqrt(k1*k1+k2*k2),b2+d*k1/sqrt(k1*k1+k2*k2));
}
}
return 0;
}