//一个小的技巧就是对于三角形的三点 开出一个6点的数组 这样用取模就方便操作了 //再就是用差乘求面积,设定p0原点后按顺时针防线连线求面积 //另外对于方程2,求ans1和ans2的坐标的时候,利用等比公式会方便许多 //degbug的时候没有区分大小写c 耽误了相当长的时间,以后命名变量的时候也要注意 #include <iostream> #include <cstdio> #include <cmath> using namespace std; const double E=1e-12; struct Point{ double x,y; }; int P,T; Point p[6]; double S,C; void read(){ for(int i=0;i<3;i++){ cin>>p[i].x>>p[i].y; p[i+3]=p[i]; } return ; } double CrossProduct(const Point &p1,const Point &p2,const Point &p3){ return (p2.x-p1.x)*(p3.y-p1.y)-(p2.y-p1.y)*(p3.x-p1.x); } double dis(const Point &p1,const Point& p2){ return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); } double area(){ double s=0; Point p0={0,0}; for(int i=0;i<3;i++) s+=CrossProduct(p0,p[i],p[(i+1)%3]); return s; } double perimeter(){ double c=0; for(int i=0;i<3;i++){ c+=dis(p[i],p[(i+1)%3]); } return c; } Point Pos(const Point &i,const Point &j,double l){ // cout<<"LEN: "<<l<<endl; Point x={0,0}; double d=dis(i,j); if(i.x-j.x) x.x=i.x-l/d*(i.x-j.x); else x.x=i.x; if(i.y-j.y) x.y=i.y-l/d*(i.y-j.y); else x.y=i.y; return x; } int dbcmp(const double & x){ if(x>-E&&x<E) return 0; return x>0?1:-1; } int main() { freopen("i.txt","r",stdin); double l,l1,l2; Point ans1,ans2; cin>>P; while(P--){ cin>>T; read(); S=fabs((area()/2)/2); C=perimeter()/2; // cout<<S<<" "<<C<<endl; for(int i=0;i<3;i++){ double sina=2*(2*S)/dis(p[i],p[(i+1)%3])/dis(p[i],p[(i+2)%3]); double b=-C,c=2*S/sina; // cout<<"Flag: "<<b<<" "<<c<<endl; // cout<<"sin: "<<sina<<endl; // cout<<"S: "<<dis(p[i],p[(i+1)%3])<<" "<<dis(p[i],p[(i+2)%3])<<endl; if(dbcmp(b*b-4*c-0.0)<0) continue; l=(-b+sqrt(b*b-4*c))/2; // cout<<"L: "<<l<<" "<<C-l<<endl; l1=dis(p[i],p[(i+1)%3]); l2=dis(p[i],p[(i+2)%3]); // cout<<"l1 l2: "<<l1<<" "<<l2<<endl; // break; // cout<<l2-l<<" "<<l1-(C-l)<<endl; if(dbcmp(l1-l)>=0&&dbcmp(l2-(C-l))>=0){ ans1=Pos(p[i],p[(i+1)%3],l); ans2=Pos(p[i],p[(i+2)%3],C-l); // cout<<"yes"<<endl; } else if(dbcmp(l2-l)>=0&&dbcmp(l1-(C-l))>=0){ ans1=Pos(p[i],p[(i+2)%3],l); ans2=Pos(p[i],p[(i+1)%3],C-l); // cout<<"yes"<<endl; } else continue; // cout<<"POINT: "<<"("<<ans1.x<<","<<ans1.y<<")"<<" " // <<"("<<ans2.x<<","<<ans2.y<<")"<<endl; { // (x-x1)/(x2-x1)=(y-y1)/(y2-y1) double A,B,C; if(dbcmp(ans1.x-ans2.x)==0){ A=1; B=0; C=ans1.x; } else if(dbcmp(ans1.y-ans2.y)==0){ A=1; B=0; C=ans1.y; } else{ double X=ans2.x-ans1.x,Y=ans2.y-ans1.y,K; A=Y; B=-X; C=ans1.x*Y-X*ans1.y; if(dbcmp(A-0.0)<0){ A=-A; B=-B; C=-C; } K=sqrt(A*A+B*B); // cout<<"ANS:"<<A<<" "<<B<<" "<<C<<endl; // cout<<"K: "<<K<<endl; A/=K; B/=K; C/=K; // A=(A*100000+0.5)/100000; // C=(C*100000+0.5)/100000; // C=(C*100000+0.5)/100000; } cout<<T<<" "; printf("%.5lf %.5lf %.5lf\n",A,B,C); break; } break; } } return 0; }