用c++判断两圆的位置关系DescriptionOne day,Lby’s girlfriend give him two circle,these two circle can be expressed as (x ,y,r ),where x,y is the center coordinate,and r is the radius.Now Lby wants to know the relation of these two circle,so

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/02 17:07:30
用c++判断两圆的位置关系DescriptionOne day,Lby’s girlfriend give him two circle,these two circle can be expressed as (x ,y,r ),where x,y is the center coordinate,and r is the radius.Now Lby wants to know the relation of these two circle,so

用c++判断两圆的位置关系DescriptionOne day,Lby’s girlfriend give him two circle,these two circle can be expressed as (x ,y,r ),where x,y is the center coordinate,and r is the radius.Now Lby wants to know the relation of these two circle,so
用c++判断两圆的位置关系
Description
One day,Lby’s
girlfriend give him two circle,these two circle can be expressed as (x ,y,r ),
where x,y is the center coordinate,and r is the radius.Now Lby wants to know
the relation of these two circle,so as to guess the intimation of girlfriend.
The relation of two circle may be :“coincide”(重合) ,“containing”(包含) ,“internally-tangent”(内切) ,“intersection”(相交) ,“externally-tangent”(外切) ,“disjoint”(相离) .
Input
Two line,each
contains three 32-bit integer x,y,r,described as the problem.
Output
A string indicate
the relation of these two circle(without quotation mark)
Sample Input
Copy sample input to clipboard
0 0 2
0 4 2
Sample Output
externally-tangent
代码如下
#include
#include
using namespace std;
int main ()
{
\x09int x1,y1,r1;
\x09int x2,y2,r2;
\x09
\x09cin >> x1 >> y1 >> r1;
\x09cin >> x2 >> y2 >> r2;
\x09
\x09float s1 = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
\x09int s2 = r1 + r2;
\x09int s3 = abs(r1 - r2);
\x09
\x09if(s1 > s2)
\x09\x09cout

用c++判断两圆的位置关系DescriptionOne day,Lby’s girlfriend give him two circle,these two circle can be expressed as (x ,y,r ),where x,y is the center coordinate,and r is the radius.Now Lby wants to know the relation of these two circle,so
浮点数是大概数,整数确定数,不能直接比较是否 相等的.如 s1==s2 等类似的比较结果与你需要的可能不同.
可以把 s1 == s2 及其它类似比较 换成 判断 两数差 的绝对值 是否小于 一个极小的常数;
例如:if( s1==s2) 换成 if( abs( s1-s2) < 0.0001)