已知三点坐标,求外接圆圆心坐标与半径。
a=((y2-y1)*(y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1)*(y2*y2-y1*y1+x2*x2-x1*x1))/(2.0*((x3-x1)*(y2-y1)-(x2-x1)*(y3-y1)));
b=((x2-x1)*(x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1)*(x2*x2-x1*x1+y2*y2-y1*y1))/(2.0*((y3-y1)*(x2-x1)-(y2-y1)*(x3-x1)));
r2=(x1-a)*(x1-a)+(y1-b)*(y1-b);
HDU4720:已知三点求最小覆盖圆的圆心坐标与半径。
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
int t;
scanf("%d",&t);
int Case=1;
while(t--)
{
double x,y,x3,x1,x2,y3,y1,y2,a,b,r2;
scanf("%lf%lf",&x1,&y1);
scanf("%lf%lf",&x2,&y2);
scanf("%lf%lf",&x3,&y3);
scanf("%lf%lf",&x,&y);
if((x2-x1)*(x3-x1)+(y2-y1)*(y3-y1)<0) //(x1,y1)是钝角
{
a=(x3+x2)/2.0,b=(y3+y2)/2.0;
r2=(a-x2)*(a-x2)+(b-y2)*(b-y2);
}
else if((x1-x2)*(x3-x2)+(y1-y2)*(y3-y2)<0) //(x2,y2)是钝角
{
a=(x3+x1)/2.0,b=(y3+y1)/2.0;
r2=(a-x1)*(a-x1)+(b-y1)*(b-y1);
}
else if((x1-x3)*(x2-x3)+(y1-y3)*(y2-y3)<0) //(x3,y3)是钝角
{
a=(x2+x1)/2.0,b=(y2+y1)/2.0;
r2=(a-x1)*(a-x1)+(b-y1)*(b-y1);
}
else //三角形是锐角三角形
{
a=((y2-y1)*(y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1)*(y2*y2-y1*y1+x2*x2-x1*x1))/(2.0*((x3-x1)*(y2-y1)-(x2-x1)*(y3-y1)));
b=((x2-x1)*(x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1)*(x2*x2-x1*x1+y2*y2-y1*y1))/(2.0*((y3-y1)*(x2-x1)-(y2-y1)*(x3-x1)));
r2=(x1-a)*(x1-a)+(y1-b)*(y1-b);
}
if((x-a)*(x-a)+(y-b)*(y-b)<=r2)
printf("Case #%d: Danger\n",Case++);
else
printf("Case #%d: Safe\n",Case++);
}
return 0;
}