zoj 1199 几何公式推导

链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=199

Point of Intersection

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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;


Source: Zhejiang University Local Contest 2002, Preliminary

 

————————————————————————————————————————————————————

题意很明确,就是求两圆公切线的交点

要判断什么情况下无法画公切线,其实也就是内含,与内切不行

然后推导公式,X=r2/(r1-r2)*(x2-x1)+x2;

                          Y=r2/(r1-r2)*(y2-y1)+y2;

如果你说,这怎么推?俺不会

那我可以说你就是个脑残

因为我也推不出来,找到这里才了解:

http://zhidao.baidu.com/link?url=FSE5MMeIMP8OOOEe4sSqLTZHEVLAQDd4j5gKkIZo54kMCd6TfwWFs3nOame8It1FuGpmVFdFbK3pbyhydbRco_

是不是脑残?中学数学都不会,丢不丢人?

楼主就是个脑残模板,就这公式推了一天

这模板希望永远别使用

——————————————————————————————————————————————————————

 1 #include <math.h>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <stdlib.h>
 5 #include <iostream>
 6 
 7 using namespace std;
 8 
 9 #define eps 1e-8
10 
11 typedef struct point
12 {
13     double x;
14     double y;
15 }point;
16 
17 double dy(double x,double y){ return x>y+eps; }
18 double xy(double x,double y){ return x<y-eps; }
19 double dyd(double x,double y){ return x>y-eps; }
20 double xyd(double x,double y){ return x<y+eps; }
21 double dd(double x,double y){ return fabs(x-y)<eps; }
22 
23 double dist(point a,point b)
24 {
25     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));//virtual
26 }
27 
28 int main()
29 {
30     int t;
31     point o1,o2;
32     double r1,r2;
33     scanf("%d",&t);
34     while(t--)
35     {
36         double x1,x2,y1,y2,r3,r4;
37         scanf("%lf%lf%lf",&x1,&y1,&r3);
38         scanf("%lf%lf%lf",&x2,&y2,&r4);
39         if(dy(r3,r4))
40         {
41             o1.x=x1;o2.x=x2;
42             o1.y=y1;o2.y=y2;
43             r1=r3;  r2=r4;
44         }
45         else
46         {
47             o1.x=x2;o2.x=x1;
48             o1.y=y2;o2.y=y1;
49             r1=r4;  r2=r3;
50         }
51         if(dd(r1,r2) || xyd(dist(o1,o2)+r2,r1))
52             printf("Impossible.
");
53         else
54         {
55             double x=(r2/(r1-r2))*(o2.x-o1.x)+o2.x;
56             double y=(r2/(r1-r2))*(o2.y-o1.y)+o2.y;
57             printf("%.2lf %.2lf
",x,y);
58         }
59     }
60     return 0;
61 }
View Code
原文地址:https://www.cnblogs.com/ccccnzb/p/3923122.html