⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 where is the little jgshining(三角形外接圆圆心).cpp

📁 杭电acm解题报告2001---2099.
💻 CPP
字号:
#include <cstdio>

struct Point
{
	double x,y;
	bool operator == (const Point &a) const
	{
		if (x == a.x && y == a.y) {
			return true;
		}
		return false;
	}
}ps[4],cc;

void  circle_center(Point &center,Point pt[3],double &radiu) 
{
	double  x1,x2,x3,y1,y2,y3;
	double  x  =  0;
	double  y  =  0;
	
	x1  =  pt[0].x;
	x2  =  pt[1].x;
	x3  =  pt[2].x;
	y1  =  pt[0].y;
	y2  =  pt[1].y;
	y3  =  pt[2].y;
	
	x=((y2-y1)*(y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1)*(y2*y2-y1*y1+x2*x2-x1*x1))/(2*(x3-x1)*(y2-y1)-2*((x2-x1)*(y3-y1)));
	y=((x2-x1)*(x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1)*(x2*x2-x1*x1+y2*y2-y1*y1))/(2*(y3-y1)*(x2-x1)-2*((y2-y1)*(x3-x1)));
	
	center.x  =  x  ;
	center.y  =  y  ;
	radiu  =  (pt[0].x-x)*(pt[0].x-x)  +  (pt[0].y-y)*(pt[0].y-y);
	
}

double Cross(const Point & a, const Point & b, const Point & o)
{return (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y);}

int main()
{
	int t;
	scanf("%d",&t);
	while (t--) {
		for (int i=0;i<3;i++) {
			scanf("%lf %lf",&ps[i].x,&ps[i].y);
		}
		if (ps[0] == ps[1] && ps[1] == ps[2]) {
			cc = ps[0];
		}
		else if (ps[0] == ps[1]) {
			cc.x = (ps[0].x + ps[2].x)/2.0;
			cc.y = (ps[0].y + ps[2].y)/2.0;
		}
		else if (ps[1] == ps[2]) {
			cc.x = (ps[0].x + ps[2].x)/2.0;
			cc.y = (ps[0].y + ps[2].y)/2.0;
		}
		else if (ps[0] == ps[2]) {
			cc.x = (ps[1].x + ps[2].x)/2.0;
			cc.y = (ps[1].y + ps[2].y)/2.0;
		}
		else {
			double r;
			if (Cross(ps[0],ps[1],ps[2]) == 0) {
				printf("No this position\n");
				continue;
			}
			circle_center(cc,ps,r);
		}
		
		printf("%.1lf %.1lf\n",cc.x,cc.y);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -