题目链接:http://poj.org/problem?id=1673
AC代码:
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const double eps = 1e-;
const double pi = acos(-1.0);
int sgn(double x)
{
if(fabs(x) < eps) return ;
else return x < ? - : ;
}
struct Point{
double x, y;
Point(){}
Point(double _x, double _y){
x = _x, y = _y;
}
bool operator == (Point b) const{
return sgn(x - b.x) == && sgn(y - b.y) == ;
}
bool operator < (Point b)const{
return sgn(x - b.x) == ? sgn(y - b.y < ) : x < b.x;
}
Point operator - (const Point &b)const{
return Point(x - b.x, y - b.y);
}
//²æ»ý
double operator ^(const Point &b){
return x * b.y - y * b.x;
}
//µã»ý
double operator *(const Point &b){
return x * b.x + y * b.y;
}
double len(){
return hypot(x, y);
}
double len2(){
return x * x + y * y;
}
double distant(Point p){
return hypot(x - p.x, y - p.y);
}
Point operator + (const Point &b)const{
return Point (x + b.x, y + b.y);
}
Point operator * (const double &k)const{
return Point(x * k, y * k);
}
Point operator / (const double &k)const{
return Point(x / k, y / k);
}
Point rotate(Point p, double angle){
Point v = (*this) - p;
double c = cos(angle), s = sin(angle);
return Point(p.x + v.x * c - v.y * s, p.y + v.x * s + v.y * c);
}
};
Point GetLineIntersection(Point P, Point v, Point Q, Point w){
Point u = P - Q;
double t =(w^u)/(v^w);
return P + v*t;
}
int main()
{
Point A, B, C;
int n;
scanf("%d",&n);
while(n--)
{
scanf("%lf %lf %lf %lf %lf %lf",&A.x, &A.y, &B.x, &B.y, &C.x, &C.y);
Point v = B,u = C;
v = v.rotate(A, pi / 2.0), u = u.rotate(B, pi / 2.0);
Point c = GetLineIntersection(C, v - A, A, u - B);
printf("%.4f %.4f\n",c.x + eps, c.y + eps);
}
return ;
}