Created
November 7, 2016 14:29
-
-
Save wowoto9772/a1ab59a0cd0b36697c0ba7be4c68ad51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <algorithm> | |
#define ll long long | |
using namespace std; | |
struct point{ | |
double x, y; | |
point(double x = 0, double y = 0) :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.x - B.x, A.y - B.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); | |
} | |
point Meet(point &A, point &B, point &C, point &D){ | |
// line AB, line CD | |
point ret; | |
if (fabs(A.x - B.x) < 1e-9){ | |
ret.x = A.x; | |
point delta = D - C; | |
ret.y = delta.y / delta.x * (ret.x - C.x) + C.y; | |
} | |
else if (fabs(C.x - D.x) < 1e-9){ | |
ret.x = C.x; | |
point delta = B - A; | |
ret.y = delta.y / delta.x * (ret.x - A.x) + A.y; | |
} | |
else{ | |
point dAB = B - A, dCD = D - C; | |
// occured over flow | |
double mAB = dAB.y / dAB.x, mCD = dCD.y / dCD.x; | |
/* | |
dAB.y / dAB.x * (x - A.x) + A.y | |
= dCD.y / dCD.x * (x - C.x) + C.y | |
mAB * x - A.x * mAB + A.y | |
= mCD * x - C.x * mCD + C.y | |
*/ | |
ret.x = (A.x * mAB - A.y - C.x * mCD + C.y) / (mAB - mCD); | |
if (ret.x == -0.0)ret.x = 0.0; | |
ret.y = mAB*(ret.x - A.x) + A.y; | |
} | |
return ret; | |
} | |
int main(){ | |
int t; | |
scanf("%d", &t); | |
while (t--){ | |
point A, B, C; | |
scanf("%lf %lf %lf %lf %lf %lf", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y); | |
point dAC = C - A; | |
point F = C; | |
F.x -= dAC.y; | |
F.y += dAC.x; | |
point dCA = A - C; | |
point G = F + dCA; | |
point dCB = B - C; | |
point J = B; | |
J.x -= dCB.y; | |
J.y += dCB.x; | |
point H = J - dCB; // -dCB = dBC | |
point dAB = B - A; | |
point D = A; | |
D.y -= dAB.x; | |
D.x += dAB.y; | |
point E = D + dAB; | |
point L = (G + D) / 2; | |
point M = (E + J) / 2; | |
point N = (F + H) / 2; | |
// seek line AL & line BM meeting points | |
point ExoCntr = Meet(A, L, M, B); | |
printf("%.4lf %.4lf\n", ExoCntr.x, ExoCntr.y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment