三点坐标确定圆心坐标

时间:2021-08-11 19:02:51
 
 
 
struct Point
{
double x,y;
friend Point operator - (Point a,Point b) //重载友元运算符
{
Point temp;
temp.x = a.x - b.x;
temp.y = a.y - b.y;
return temp;
}
};

Point get_pc1(Point p1, Point p2, Point p3)  //求圆心
{
double a, b, c, d, e, f;
Point p;
a = 2*(p2.x-p1.x);
b = 2*(p2.y-p1.y);
c = p2.x*p2.x+p2.y*p2.y-p1.x*p1.x-p1.y*p1.y;
d = 2*(p3.x-p2.x);
e = 2*(p3.y-p2.y);
f = p3.x*p3.x+p3.y*p3.y-p2.x*p2.x-p2.y*p2.y;
p.x = (b*f-e*c)/(b*d-e*a);
p.y = (d*c-a*f)/(b*d-e*a);
r = sqrt((p.x-p1.x)*(p.x-p1.x)+(p.y-p1.y)*(p.y-p1.y));//半径
return p;
}