uva 190 Circle Through Three Points(三点求外心)

题意:每组给出三个点的坐标,求外接圆标准方程和一般方程;

思路:求三角形的外心。外心到三点中任意一点距离为半径。外心为垂直平分线的交点。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const double epsi=1e-10;
inline int sign(const double &x){
    if(x>epsi) return 1;
    if(x<-epsi) return -1;
    return 0;
}
struct point{
    double x,y;
    point(double xx=0,double yy=0):x(xx),y(yy){}
    point operator +(const point &op2) const{
        return point(x+op2.x,y+op2.y);
    }
    point operator -(const point &op2) const{
        return point(x-op2.x,y-op2.y);
    }
    point operator *(const double &d) const{
        return point(x*d,y*d);
    }
    point operator /(const double &d) const{
        return point(x/d,y/d);
    }
    double operator ^(const point &op2) const{
        return x*op2.y-y*op2.x;
    }
};
inline double sqr(const double &x){
    return x*x;
}
inline double mul(const point &p0,const point &p1,const point &p2){
    return (p1-p0)^(p2-p0);
}
inline double dis2(const point &p0,const point &p1){
    return sqr(p0.x-p1.x)+sqr(p0.y-p1.y);
}
inline double dis(const point &p0,const point &p1){
    return sqrt(dis2(p0,p1));
}
struct Line{              //中垂线
    double A,B,C;
    Line(double a=0,double b=0,double c=0):A(a),B(b),C(c){}
    point cross(const Line &a) const{  //计算另一条中垂线与中垂线a的交点
        double xx=-(C*a.B-a.C*B)/(A*a.B-a.A*B);
        double yy=-(C*a.A-a.C*A)/(B*a.A-a.B*A);
        return point(xx,yy);
    }
};
inline double circumcenter(const point &p1,const point &p2,const point &p3,point &p)
{
    p=p1+Line(p3.x-p1.x,p3.y-p1.y,-dis2(p3,p1)/2.0).cross(Line(p2.x-p1.x,p2.y-p1.y,-dis2(p2,p1)/2.0));//圆心p
    return dis(p,p1);  //返回半径
}
point p1,p2,p3,p4,p;
inline int print(double x){
    if(x>0) printf(" + %.3f",x);
    else printf(" - %.3f",-x);
    return 0;
}
int main()
{
   while(scanf("%lf%lf%lf%lf%lf%lf",&p1.x,&p1.y,&p2.x,&p2.y,&p3.x,&p3.y)!=EOF)
   {
       double r=circumcenter(p1,p2,p3,p);
       printf("(x");
       print(-p.x);
       printf(")^2 + (y");
       print(-p.y);
       printf(")^2 =");
       printf(" %.3f",r);
       printf("^2\n");

       printf("x^2 + y^2");
       print(-2*p.x);
       printf("x");
       print(-2*p.y);
       printf("y");
       print(sqr(p.x)+sqr(p.y)-sqr(r));
       printf(" = 0\n\n");
   }
   return 0;
}

 

posted on 2015-06-03 19:48  大树置林  阅读(288)  评论(0编辑  收藏  举报

导航