poj1329Circle Through Three Points(三角形外接圆)

链接

套模板

不知道有没有x,y=0情况,不过这种情况都按+号输出的。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct Point
{
double x,y;
Point (double x=,double y =):x(x),y(y){}
}p[];
struct Circle
{
Point center;
double r;
};
typedef Point pointt;
pointt operator - (Point a,Point b)
{
return Point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
double dis(Point a)
{
return a.x*a.x+a.y*a.y;
}
double cross(Point a,Point b)
{
return a.x*b.y-a.y*b.x;
}
double area()
{
return fabs(cross(p[]-p[],p[]-p[]))/;
}
struct Circle Circumcircle()
{
Circle tmp;
double a,b,c,c1,c2;
double xa,ya,xb,yb,xc,yc;
a = sqrt(dis(p[]-p[]));
b = sqrt(dis(p[]-p[]));
c = sqrt(dis(p[]-p[]));
//根据s = a*b*c/R/4,求半径
tmp.r = (a*b*c)/(area()*4.0);
xa = p[].x;
ya = p[].y;
xb = p[].x;
yb = p[].y;
xc = p[].x;
yc = p[].y;
c1 = (dis(p[])-dis(p[]))/;
c2 = (dis(p[])-dis(p[]))/;
tmp.center.x = (c1*(ya-yc)-c2*(ya-yb))/((xa-xb)*(ya-yc)-(xa-xc)*(ya-yb));
tmp.center.y = (c1*(xa-xc)-c2*(xa-xb))/((ya-yb)*(xa-xc)-(ya-yc)*(xa-xb));
return tmp;
}
int main()
{
while(scanf("%lf%lf%lf%lf%lf%lf",&p[].x,&p[].y,&p[].x,&p[].y,&p[].x,&p[].y)!=EOF)
{
Circle cc = Circumcircle();
double r = cc.r;
char c1,c2;
c1 = dcmp(cc.center.x)>?'-':'+';
c2 = dcmp(cc.center.y)>?'-':'+';
printf("(x %c %.3f)^2 + (y %c %.3f)^2 = %.3f^2\n",c1,fabs(cc.center.x),c2,fabs(cc.center.y),r);
double s = r*r-cc.center.x*cc.center.x-cc.center.y*cc.center.y;
char c3 = dcmp(s)>?'-':'+';
printf("x^2 + y^2 %c %.3fx %c %.3fy %c %.3f = 0\n",c1,fabs(cc.center.x*),c2,fabs(cc.center.y*),c3,fabs(s));
puts("");
}
return ;
}
上一篇:Android应用中使用百度地图API定位自己的位置(二)


下一篇:ADO.NET一小记-select top 参数问题