三点求圆心以及半径

三点求圆心以及半径模板

double X,Y,R;
struct Point{
    double x,y;
}pp[maxn];
double dis(Point x,Point y)
{
    return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));
}

void solve(Point a,Point b,Point c)//三点共圆圆心公式

{

    X=( (a.x*a.x-b.x*b.x+a.y*a.y-b.y*b.y)*(a.y-c.y)-(a.x*a.x-c.x*c.x+a.y*a.y-c.y*c.y)*(a.y-b.y) ) / (2*(a.y-c.y)*(a.x-b.x)-2*(a.y-b.y)*(a.x-c.x));
    Y=( (a.x*a.x-b.x*b.x+a.y*a.y-b.y*b.y)*(a.x-c.x)-(a.x*a.x-c.x*c.x+a.y*a.y-c.y*c.y)*(a.x-b.x) ) / (2*(a.y-b.y)*(a.x-c.x)-2*(a.y-c.y)*(a.x-b.x));
    R=sqrt((X-a.x)*(X-a.x)+(Y-a.y)*(Y-a.y));

    //return (Point){x,y};

}

你可能感兴趣的:(算法模板)