HDU1791三点确定一个圆

it2024-10-13  19

1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <cstdlib> 6 #include <algorithm> 7 #include <vector> 8 #include <stack> 9 #include <queue> 10 #include <cassert> 11 #include <set> 12 #include <sstream> 13 #include <map> 14 using namespace std ; 15 #ifdef DeBUG 16 #define bug assert 17 #else 18 #define bug // 19 #endif 20 #define zero {0} 21 #define INF 2000000000 22 #define EPS 1e-10 23 inline int sgn(double x)//sgn函数符号判断 ,小于给定精度判零 24 { 25 return fabs(x) < EPS ? 0 :(x < 0 ? -1 : 1); 26 } 27 struct POINT 28 { 29 double x; 30 double y; 31 POINT() 32 { 33 } 34 POINT(double a,double b):x(a),y(b) 35 { 36 } 37 }; 38 double dist(POINT p,POINT r) 39 { 40 return sqrt((p.x-r.x)*(p.x-r.x)+(p.y-r.y)*(p.y-r.y)); 41 } 42 bool cocircle(POINT p1,POINT p2,POINT p3,POINT &q,double &r) 43 { 44 double x12=p2.x-p1.x; 45 double y12=p2.y-p1.y; 46 double x13=p3.x-p1.x; 47 double y13=p3.y-p1.y; 48 double z2=x12*(p1.x+p2.x)+y12*(p1.y+p2.y); 49 double z3=x13*(p1.x+p3.x)+y13*(p1.y+p3.y); 50 double d=2.0*(x12*(p3.y-p2.y)-y12*(p3.x-p2.x)); 51 if(abs(d)<EPS) //共线,圆不存在 52 return false; 53 q.x=(y13*z2-y12*z3)/d; 54 q.y=(x12*z3-x13*z2)/d; 55 r=dist(p1,q); 56 return true; 57 } 58 int main() 59 { 60 #ifdef DeBUGn 61 62 freopen("C:\\Users\\Sky\\Desktop\\1.in","r",stdin); 63 #endif 64 int T; 65 double x1,x2,x3,y1,y2,y3; 66 scanf("%d",&T); 67 while(T--) 68 { 69 POINT xin; 70 double r; 71 cin>>x1>>y1>>x2>>y2>>x3>>y3; 72 /* 73 if(sgn((x3-x1)*(y2-y1)-(y3-y1)*(x2-x1))==0) 74 printf("No this position\n"); 75 else 76 {*/ 77 if(cocircle(POINT(x1,y1),POINT(x2,y2),POINT(x3,y3),xin,r)) 78 printf("%.1lf %.1lf\n",xin.x,xin.y); 79 else if((x1==x2&&y1==y2)||(x1==x3&&y1==y3)||(x2==x3&&y2==y3))//知道数据了这里偷个懒呵呵,应判断两点中点 80 printf("%.1lf %.1lf\n",(x1+x2+x3)/2,(y1+y2+y3)/2); 81 else 82 printf("No this position\n"); 83 //} 84 } 85 return 0; 86 } View Code

 

转载于:https://www.cnblogs.com/Skyxj/p/3227904.html

相关资源:数据结构—成绩单生成器
最新回复(0)