poj 1329 计算几何

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<map>
#include<set>
using namespace std;
const double eps=1e-10;
struct Point {
  double x,y;
  Point(double x=0,double y=0):x(x),y(y) {}
  void init(){
     scanf("%lf%lf",&x,&y);
  }
  Point operator + (const Point &a) const{
     return Point(x+a.x,y+a.y);
  }
  Point operator - (const Point &a) const{
    return Point(x-a.x,y-a.y);
  }
  double operator ^ (const Point &a) const{
    return x*a.y- y*a.x;
  }
  Point operator * (const double &a) const{
    return Point(x*a,y*a);
  }
  Point operator / (const double &a) const{
     return Point(x/a,y/a);
  }
};
inline int sign(double x){
  if(x>eps) return 1;
  else if(x<-eps) return -1;
  else return 0;
}
inline double dob(double x){
   return x*x;
}
inline double dis2(Point &a,Point &b){
    return dob(a.x-b.x)+dob(a.y-b.y);
}
inline double dis(Point &a ,Point &b){
   return sqrt(dis2(a,b));
}

struct straightline{
   double A,B,C;
   straightline(double a=0,double b=0,double c=0):A(a),B(b),C(c){}
   Point cross(straightline &p){
      double xx= -(C * p.B - B * p.C)/(A * p.B - B * p.A);
      double yy= -(C * p.A - A * p.C)/(B * p.A - A * p.B);
      return Point(xx,yy);
   }
};

Point p[4],center;
double dia;
void circumcenter(Point &a,Point &b,Point &c){\
    straightline tp1,tp2;
    tp1=straightline(c.x-a.x, c.y-a.y, -dis2(c,a)/2.0);
    tp2=straightline(b.x-a.x, b.y-a.y, -dis2(b,a)/2.0);
    center=a+tp1.cross(tp2);
    dia=dis(center,a);
}
char deal(double &x){
   if(sign(x)>=0)return '-';
   x=-x;return '+';
}
void prf(){
    char t1,t2,t3;
    t1=deal(center.x);
    t2=deal(center.y);

    printf("(x %c %.3f)^2 + (y %c %.3f)^2 = %.3f^2\n",t1,center.x,t2,center.y,dia);
    double ans=dob(dia)-dob(center.x)-dob(center.y);
    t3=deal(ans);
    printf("x^2 + y^2 %c %.3fx %c %.3fy %c %.3f = 0\n\n",t1,center.x*2,t2,center.y*2,t3,ans);

}
int main()
{

//     freopen("in.in","r",stdin);
     while(~scanf("%lf%lf",&p[0].x,&p[0].y)){
        p[1].init();p[2].init();
        circumcenter(p[0],p[1],p[2]);
        prf();
     }
     return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值