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 119 120 121 122 123 124
| #include<bits/stdc++.h> using namespace std; #define ll long long #define PI acos(-1) struct Point{ ll x,y; bool operator < (const Point a) { return x<a.x; } }pp[3]; struct line{ Point s,t; }; bool in(ll x2,ll y2,ll x3,ll y3,ll x0,ll yy0){ if((x0-x2)*(y3-y2)==(x3-x2)*(yy0-y2)&&min(x2,x3)<=x0&&x0<=max(x2,x3)&&min(y2,y3)<=yy0&&yy0<=max(y2,y3)){ return true; }else{ return false; } }
int judge(line l1,line l2,line l3,Point p) { if(in(l1.s.x,l1.s.y,l1.t.x,l1.t.y,p.x,p.y))return 1; if(in(l2.s.x,l2.s.y,l2.t.x,l2.t.y,p.x,p.y))return 2; if(in(l3.s.x,l3.s.y,l3.t.x,l3.t.y,p.x,p.y))return 3; return -1; } double dis(Point a,Point b) { return sqrt(1ll*(b.x-a.x)*(b.x-a.x)+1ll*(b.y-a.y)*(b.y-a.y)); } void getans(Point s,Point t,double x) { printf("%.12lf %.12lf\n",s.x+(t.x-s.x)*x/dis(s,t),s.y+(t.y-s.y)*x/dis(s,t)); } int main(){ int t; scanf("%d",&t); while(t--) { ll x1,x2,x3,y1,y2,y3,px,py; scanf("%lld%lld%lld%lld%lld%lld%lld%lld",&x1,&y1,&x2,&y2,&x3,&y3,&px,&py); if(px==x1&&py==y1) { printf("%.12lf %.12lf\n",1.0*(x2+x3)/2,1.0*(y2+y3)/2); continue; } if(px==x2&&py==y2) { printf("%.12lf %.12lf\n",1.0*(x1+x3)/2,1.0*(y1+y3)/2); continue; } if(px==x3&&py==y3) { printf("%.12lf %.12lf\n",1.0*(x2+x1)/2,1.0*(y2+y1)/2); continue; } pp[0]={x1,y1}; pp[1]={x2,y2}; pp[2]={x3,y3}; sort(pp,pp+3); Point p1=pp[0]; Point p2=pp[1]; Point p3=pp[2]; Point p = {px,py}; line l1 = line{p1,p2}; line l2 = line{p2,p3}; line l3 = line{p1,p3}; double lenl1 = dis(l1.s,l1.t); double lenl2 = dis(l2.s,l2.t); double lenl3 = dis(l3.s,l3.t); double P=(lenl1+lenl2+lenl3)/2; double S=sqrt(P*(P-lenl1)*(P-lenl2)*(P-lenl3)); int l = judge(l1,l2,l3,p); if(l==-1){printf("-1\n");continue;} else if(l==1) { if(dis(p1,p)>lenl1/2) { double d = dis(p,p1); double x = S/(d*(sin(acos((lenl1*lenl1+lenl3*lenl3-lenl2*lenl2)/(2*lenl1*lenl3))))); getans(p1,p3,x); } else { double d = dis(p,p2); double x = S/(d*(sin(acos((lenl1*lenl1+lenl2*lenl2-lenl3*lenl3)/(2*lenl1*lenl2))))); getans(p2,p3,x); } } else if(l==2) { if(dis(p,p2)>lenl2/2) { double d = dis(p2,p); double x = S/(d*(sin(acos((lenl1*lenl1+lenl2*lenl2-lenl3*lenl3)/(2*lenl1*lenl2))))); getans(p2,p1,x); } else { double d = dis(p,p3); double x = S/(d*(sin(acos((lenl2*lenl2+lenl3*lenl3-lenl1*lenl1)/(2*lenl2*lenl3))))); getans(p3,p1,x); } } else if(l==3) { if(dis(p,p3)>=lenl3/2) { double d = dis(p,p3); double x = S/(d*(sin(acos((lenl2*lenl2+lenl3*lenl3-lenl1*lenl1)/(2*lenl2*lenl3))))); getans(p3,p2,x); } else { double d = dis(p,p1); double x = S/(d*(sin(acos((lenl1*lenl1+lenl3*lenl3-lenl2*lenl2)/(2*lenl1*lenl3))))); getans(p1,p2,x); } } } }
|