判断点与圆的位置关系(点在圆内,点在圆外)

//定义一个Point类,其属性包括点的坐标,提供计算
//两点之间距离的方法
//定义一个Circle类,其属性包括圆心和半径
//创建两个圆形对象,提示用户输入圆心坐标和半径,
//判断两个圆是否相交并输出结果
#include<iostream>
using namespace std;
class Point
{
public:
	void setPointt(int _x1, int _y1)
	{
		x1 = _x1;
		y1 = _y1;
	}
	int getX1()
	{
		return x1;
	}
	int getY1()
	{
		return y1;
	}

private:
	int x1;
	int y1;
};
class Circle
{
public:
	void setCircle(int _r, int _x0, int _y0)
	{
		r = _r;
		x0 = _x0;
		y0 = _y0;
	}

	//类做函数参数最好用引用
	//在圆内返回1,不在圆内返回0
	//在成员函数内可以使用c1的私有属性
	int judge(Point &p)
	{
		int dd;
		dd = (p.getX1() - x0)*(p.getX1() - x0) + (p.getY1() - y0)*(p.getY1() - y0);
		if (dd < r*r)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}

private:
	int r;
	int x0;
	int y0;

};



int main02()
{
	Circle c1;
	Point p1;
	int tag;
	c1.setCircle(2, 3, 3);
	p1.setPointt(7, 7);
	//点在圆内为1 不在圆内为0
	tag=c1.judge(p1);
	if (tag == 1)
	{
		cout << "在圆内" << endl;
	}
	else
	{
		cout << "在圆外" << endl;
	}
	system("pause");
	return 0;
}

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值