/*
* 程序的版权和版本声明部分:
* Copyright (c) 2013.烟台大学计算机学院
* All rights reserved.
* 文件名称:
* 作 者:冯冬影
* 完成日期:2014 年 5月 26日
* 版 本 号:v1.0
* 对任务及求解方法的描述部分:
* 输入描述:
* 问题描述:
* 程序输出:
*/
#include <iostream>
#include <Cmath>
using namespace std;
class Circle;
class Point
{
protected:
double x;
double y;
public:
Point(int a=0,int b=0):x(a),y(b) {}
~Point() {};
friend ostream &operator<<(ostream &output,Point &p);
friend void Vpoint(Point &p,Circle &c,Point &p1,Point &p2);
};
class Circle:public Point
{
public:
Circle(int a=0,int b=0,int c=0):Point(a,b),r(c) {}
friend void Vpoint(Point &p,Circle &c,Point &p1,Point &p2);
~Circle() {};
friend ostream &operator<<(ostream &output,Circle &c);
protected:
double r;
};
void Vpoint(Point &p,Circle &c,Point &p1,Point &p2)
{
p1.x=c.x+sqrt(c.r*c.r/(1+((c.y-p.y)/(c.x-p.x))*((c.y-p.y)/(c.x-p.x))));
p1.y=((c.y-p.y)/(c.x-p.x))*(p1.x-p.x)+p.y;
p2.x=c.x-sqrt((c.r*c.r)/(1+((c.y-p.y)/(c.x-p.x))*((c.y-p.y)/(c.x-p.x))));
p2.y=((c.y-p.y)/(c.x-p.x))*(p2.x-p.x)+p.y;
}
ostream &operator<<(ostream &output,Point &p)
{
output<<"("<<p.x<<","<<p.y<<")"<<endl;
return output;
}
ostream &operator<<(ostream &output,Circle &c)
{
output<<"圆心为:"<<"("<<c.x<<","<<c.y<<")";
output <<"圆的半径为:"<<c.r<<endl;
return output;
}
int main()
{
Point p(-2,-1),p1,p2;
Circle c(3,4,5);
Vpoint(p,c,p1,p2);
cout<<"点p:"<<p<<endl;
cout<<"圆c:"<<c<<endl;
cout<<"点与圆的交点为:"<<p1<<'\t'<<p2<<endl;
return 0;
}
运行结果