#include <iostream>
#include <string>
using namespace std;
class Point
{
private:
double m_x;
double m_y;
public:
void setXY(double x,double y)
{
m_x = x;
m_y = y;
}
int getX()
{
return m_x;
}
int getY()
{
return m_y;
}
};
class Circle
{
private:
Point m_center;
double m_r;
public:
void setR(double R)
{
m_r = R;
}
double getR()
{
return m_r;
}
void setCenter(Point center)
{
m_center = center;
}
Point getCenter()
{
return m_center;
}
};
void isInCircel(Circle &c,Point &p)
{
double distance = (c.getCenter().getX() - p.getX())*(c.getCenter().getX() - p.getX()) + (c.getCenter().getY() - p.getY())*(c.getCenter().getY() - p.getY());
double rdistance = c.getR()*c.getR();
if (distance > rdistance)
{
cout << "点在圆外"<< endl;
}
else if (distance < rdistance)
{
cout << "点在圆内"<< endl;
}
else
{
cout << "点在圆上"<< endl;
}
}
int main()
{
//创建点
Point p;
p.setXY(3,4);
Point p1;
p1.setXY(12,13);
//创建圆;
Circle c;
c.setR(12);
c.setCenter(p1);
isInCircel(c,p);
return 0;
}
类:点和圆的关系
最新推荐文章于 2023-11-02 17:35:09 发布