#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define CLR(a,v) memset(a,v,sizeof(a)) #define FOR(i,x,n) for(__typeof(x) i = (x); i != (n); i++) #define FRI(it,v) FOR(it,v.begin(),v.end()) #define FR(i,n) FOR(i,0,n) #define ALL(x) (x).begin(),(x).end() #define SZ size() #define PB push_back #define MP make_pair #define show(x) cerr<<#x<<"="< Pr; typedef long long LL; const LL INF = 1LL <<50; using namespace std; typedef complex P; typedef pair Seg; typedef vector

VP; #define eps 1e-8 #define neg(x) ( (x) < -eps) #define pos(x) ( (x) > +eps) #define eq(x, y) ( abs ( (x) - (y) ) < eps ) #define ls(x, y) ( neg ( (x) - (y) ) ) #define gt(x, y) ( pos ( (x) - (y) ) ) #define zero(x) (!neg(x) && !pos(x)) #define V(x, y) ( (y) - (x) ) double cross(P a, P b) { return imag(conj(a)*b); } double dot (P a, P b) { return real(conj(a)*b); } int sign (double x) { return pos(x)-neg(x); } bool left(P &a, P &b, P &c) { return neg(sign(cross(V(a, c),V(a, b)))); } bool onsides(P a, P b, P c, P d) { return sign(cross(V(a, c), V(a, b))) * sign(cross(V(a, d), V(a, b))) != +1; // including online } struct ltpt { bool operator ()(const P &a, const P &b) const { return ls(imag(a),imag(b)) || (eq(imag(a),imag(b)) && ls(real(a),real(b))); } }; vector

intersect(P a, P b, P c, P d) { vector

v; if (!onsides(a, b, c, d) || !onsides(c, d, a, b)) return v; double d1 = cross(V(a, c), V(a, b)); double d2 = cross(V(a, d), V(a, b)); if (d1 == d2) return v; P ans = (d1*d - d2*c)/(d1 - d2); v.PB(ans); return v; } bool online(P &p, P &a, P &b, bool including=true) { if (eq(p, a) || eq(p, b)) return including; return (zero(cross(V(p, a), V(p, b))) && neg(dot (V(p, a), V(p, b)))); } bool isintri(P x, VP a) { FR(j,3) if (online(x, a[j], a[(j+1)%3])) return true; FR(j,3) if (sign(cross(V(x,a[(j+0)%3]), V(x,a[(j+1)%3]))) != sign(cross(V(x,a[(j+1)%3]), V(x,a[(j+2)%3])))) return false; return true; } VP a[2]; vector convex(vector

&p) { // most pnts, in counter-clockwise vector v; map added; int n = p.SZ, h = 0; FR(i, n) if ((p[i].Y < p[h].Y) || (p[i].Y == p[h].Y && p[i].X < p[h].X)) h = i; // leftmost lower point for (int r=h; v.PB(r), r=(r+1)%n, !added[h=v.back()]++; ) FR(i,n) if (i != h) // online(p[h], p[r], p[i]) dels onlines if (left(p[h], p[r], p[i]) || online(p[h], p[i], p[r])) r = i; // left(p[h], p[r], p[i]) give clockwise v.pop_back(); // to not have v[0] at the end, too return v; // FRI(it, v) WR(p[*it]); } double dot2(P a, P b) { return a.X * b.Y - a.Y * b.X; } double getArea(VP ch) { double ans = 0; FR(i,(int)ch.SZ) ans += cross(ch[i], ch[(i+1)%ch.SZ]);//, //V(ch[(i+1)%ch.SZ], ch[(i+2)%ch.SZ))); ans = abs(ans / 2.0); return ans; } double solve() { set allPoints; // Points of the given triangles FR(i,2) FR(j,3) allPoints.insert(a[i][j]); // Points of intersections FR(j0,3) FR(j1,3) { VP v = intersect(a[0][j0], a[0][(j0+1)%3], a[1][j1], a[1][(j1+1)%3]); FRI(it,v) allPoints.insert(*it); } VP goodPoints; FRI(it,allPoints) if (isintri(*it, a[0]) && isintri(*it, a[1])) goodPoints.PB(*it); if (goodPoints.SZ <= 2) return 0; vector ind = convex(goodPoints); VP ch; FRI(it, ind) { //cerr << *it << " of " << goodPoints.SZ << endl; ch.PB(goodPoints[*it]); } show(ch.SZ); FRI(it, ch) cerr << it->X << ", " << it->Y << "\t"; cerr << endl; double ans = getArea(ch); return ans; } int main() { int testn; cin >> testn; FR(testi,testn) { // read input FR(k,2) { a[k].resize(3); FR(i,3) cin >> a[k][i].X >> a[k][i].Y; } double d = solve(); printf("%0.2f\n", d); } return 0; }