1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| #include<cmath> #include<cstdio> #include<vector> #include<cassert> #include<cstring> #include<algorithm> using namespace std; using db=double; const int N=1000010,FSIZE=1<<26; char BuF[FSIZE],*InF=BuF; template<typename T>void read(T &x){ bool f=1; for(;48>*InF||*InF>57;f^=*InF++=='-'); for(x=0;47<*InF&&*InF<58;x=x*10+(*InF++^48)); if(*InF++=='.') for(db t=1;47<*InF&&*InF<58;x+=(t/=10)*(*InF++-48)); x=f?x:-x; } struct point{ db x,y; point operator-(point b){return((point){x-b.x,y-b.y});} db operator+(){return(sqrt(x*x+y*y));} }a[4],b[4]; struct matrix{ db a[3][3]; matrix operator*(matrix b){ matrix c; memset(c.a,0,sizeof(c.a)); for(int i=0;i<3;i++) for(int k=0;k<3;k++) if(a[i][k]!=0) for(int j=0;j<3;j++) c.a[i][j]+=a[i][k]*b.a[k][j]; return(c); } bool operator==(matrix b){ for(int i=0;i<3;i++) for(int j=0;j<3;j++) if(abs(a[i][j]-b.a[i][j])>1e-6){ return(0); } return(1); } }p; void solve(db a,db b,db c,db d,db e,db f,db l,db r){ db x=(b*f-c*e)/(a*e-b*d), y=(c*d-a*f)/(a*e-b*d); printf("%.8f %.8f\n",x+l,y+r); } void work(){ read(a[0].x);read(a[0].y); read(a[1].x);read(a[1].y); read(a[3].x);read(a[3].y); read(a[2].x);read(a[2].y); read(b[0].x);read(b[0].y); read(b[1].x);read(b[1].y); read(b[3].x);read(b[3].y); read(b[2].x);read(b[2].y); point d=a[2]; for(int i=0;i<4;++i){ a[i]=a[i]-d; b[i]=b[i]-d; } db ang=atan2(b[3].y-b[2].y,b[3].x-b[2].x)-atan2(a[3].y,a[3].x), dx=+(b[3]-b[2])/+(a[3]-a[2]),dy=+(b[0]-b[2])/+(a[0]-a[2]); p=(matrix){ cos(ang),sin(ang),0, -sin(ang),cos(ang),0, 0, 0,1}* (matrix){ dx, 0,0, 0,dy,0, 0, 0,1}* (matrix){ 1, 0,0, 0, 1,0, b[2].x,b[2].y,1}; solve( p.a[0][0]-1, p.a[1][0], p.a[2][0], p.a[0][1], p.a[1][1]-1, p.a[2][1], d.x,d.y); } int main(){ fread(BuF,1,FSIZE,stdin); int t; for(read(t);t--;work()); fclose(stdin); fclose(stdout); return(0); }
|