判断两个圆是否相交
#include "stdafx.h"
#include <iostream>
#include<math.h>
using namespace std;
class point {
public:
void setxy(int x,int y)
{
m_x = x;
m_y = y;
}
double point_distance(point &another)
{
int d_x = m_x - another.m_x;
int d_y = m_y - another.m_y;
double dis = sqrt(d_x*d_x + d_y * d_y);
return dis;
}
private:
int m_x;
int m_y;
};
class circle {
public:
void setr(int r)
{
m_r = r;
}
void serxy(int x, int y)
{
p.setxy(x, y);
}
bool judge(circle &another)
{
int rr = m_r + another.m_r;
double diss = p.point_distance(another.p);
if (rr > diss)
return true;
else return false;
}
private:
int m_r;
point p;
};
int main()
{
circle c1, c2;
int x, y, r;
cout << "输入第一个圆de半径" << endl;
cin >> r;
cout << "输入第一个圆的x" << endl;
cin >> x;
cout << "输入第一个圆的y" << r << endl;
cin >> y;
c1.serxy(x, y);
c1.setr(r);
cout << "输入第2个圆de半径" << endl;
cin >> r;
cout << "输入第2个圆的x" << endl;
cin >> x;
cout << "输入第2个圆的y" << endl;
cin >> y;
c2.serxy(x, y);
c2.setr(r);
if (c1.judge(c2) == true)
cout << "相交" << endl;
else cout << "不相交" << endl;
return 0;
}