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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
 #include<iostream> #include<cmath> #include<iomanip> using namespace std; struct Point{ double x,y; Point(){} Point(double x,double y):x(x),y(y){} }; typedef Point Vector; Vector operator + (Vector A,Vector B){ return Vector(A.x+B.x,A.y+B.y); } Vector operator  (Vector A,Vector B){ return Vector(A.xB.x,A.yB.y); } Vector operator * (Vector A,double p){ return Vector(A.x*p,A.y*p); } Vector operator / (Vector A,double p){ return Vector(A.x/p,A.y/p); } bool operator < (const Point& a,const Point& b){ return a.x<b.x(a.x==b.x&&a.y<b.y); } const double eps = 1e10; int dcmp(double x){ if(fabs(x)<eps) return 0; else return (x<0?1:1); } bool operator == (const Point& a,const Point& b){ return dcmp(a.xb.x)==0 && dcmp(a.yb.y)==0; }
double Dot(Vector A,Vector B){ return A.x*B.x+A.y*B.y; } double Length(Vector A){ return sqrt(Dot(A,A)); } double Angle(Vector A,Vector B){ return acos(Dot(A,B)/Length(A)/Length(B)); }
double Cross(Vector A,Vector B){ return (A.x*B.yA.y*B.x); }
double Area2(Point A,Point B,Point C){ return Cross(BA,CA); }
Vector Rotate(Vector A,double rad){ return Vector(A.x*cos(rad)A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad)); }
Vector Normal(Vector A){ double Len=Length(A); return Vector(A.y/Len,A.x/Len); }
Point GetLineIntersection(Point P,Vector v,Point Q,Vector w){ Vector u=PQ; double t=Cross(w,u)/Cross(v,w); return P+v*t; }
double DistanceToLine(Point P,Point A,Point B){ Vector v1=BA,v2=PA; return fabs(Cross(v1,v2))/Length(v1); }
double DistanceToSegment(Point P,Point A,Point B){ if(A==B) return Length(PA); Vector v1=BA,v2=PA,v3=PB; if(dcmp(Dot(v1,v2))<0) return Length(v2); else if(dcmp(Dot(v1,v3))>0) return Length(v3); else return fabs(Cross(v1,v2))/Length(v1); }
Point GetLineProjection(Point P,Point A,Point B){ Vector v=BA; return A+v*(Dot(v,PA)/Dot(v,v)); }
bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2){ double c1=Cross(a2a1,b1a1), c2=Cross(a2a1,b2a1), c3=Cross(b2b1,a1b1), c4=Cross(b2b1,a2b1); return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0; }
bool OnSegment(Point P,Point a1,Point a2){ return dcmp(Cross(a1P,a2P))==0 && dcmp(Dot(a1P,a2P))<=0; }
double PolygonArea(Point* p,int n){ double area=0; for(int i=1;i<n1;i++){ area+=Cross(p[i]p[0],p[i+1]p[0]); } return area/2; } int main(){ int n; cin>>n; while(n){ Point A,B,C,D; cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y>>D.x>>D.y; bool check1=SegmentProperIntersection(A,B,C,D); bool check2=OnSegment(A,C,D)OnSegment(B,C,D)OnSegment(C,A,B)OnSegment(D,A,B); if(check1check2){ cout<<fixed<<setprecision(10)<<GetLineIntersection(A,BA,C,DC).x<<" "<<GetLineIntersection(A,BA,C,DC).y<<"\n"; } }
}
