1 0.000 0.000 4.000 0.000 1.000 1.000 3.000 1.000
2.000 0.000
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
struct Point
{
double x,y;
Point(double x = 0, double y = 0) : x(x),y(y) {};
void input()
{
scanf("%lf %lf",&x,&y);
}
} point[5];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
for(int i = 0; i < 4; i++)
point[i].input();
double a1 = point[1].y - point[0].y;
double b1 = point[0].x - point[1].x;
double c1 = point[0].y * point[1].x - point[0].x * point[1].y;
double a2,b2,c2;
double x,y,k;
k = -2.0 * (a1 * point[2].x + b1 * point[2].y + c1) / (a1 * a1 + b1 * b1);
x = point[2].x + k * a1;
y = point[2].y + k * b1;
a2 = point[3].y - y;
b2 = x - point[3].x;
c2 = y * point[3].x - point[3].y * x;
double x1 = (c2 * b1 - c1 * b2) / (a1 * b2 - a2 * b1);
double y1 = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
if(b1 == 0) x1 = point[0].x;//其实不用考虑这两种情况也能AC,因为不考虑也不影响结果;
if(a1 == 0) y1 = point[0].y;
printf("%.3lf %.3lf\n",x1,y1);
}
return 0;
}
原文:http://blog.csdn.net/zsgg_acm/article/details/38834619