uva11178

Problem D
Morley’s Theorem
Input: 
Standard Input

Output: Standard Output

 Morley’s theorem states that that the lines trisecting the angles of an arbitrary plane triangle meet at the vertices of an equilateral triangle. For example in the figure below the tri-sectors of angles A, B and C has intersected and created an equilateral triangle DEF.

 

Of course the theorem has various generalizations, in particular if all of the tri-sectors are intersected one obtains four other equilateral triangles. But in the original theorem only tri-sectors nearest to BC are allowed to intersect to get point D, tri-sectors nearest to CA are allowed to intersect point E and tri-sectors nearest to AB are intersected to get point F. Trisector like BD and CE are not allowed to intersect. So ultimately we get only one equilateral triangle DEF. Now your task is to find the Cartesian coordinates of D, E and F given the coordinates of A, B, and C.

 

Input

First line of the input file contains an integer N (0<N<5001) which denotes the number of test cases to follow. Each of the next lines contain sixintegers . This six integers actually indicates that the Cartesian coordinates of point A, B and C are  respectively. You can assume that the area of triangle ABC is not equal to zero,  and the points A, B and C are in counter clockwise order.

 

Output

For each line of input you should produce one line of output. This line contains six floating point numbers  separated by a single space. These six floating-point actually means that the Cartesian coordinates of D, E and F are  respectively. Errors less than   will be accepted.

 

Sample Input   Output for Sample Input

2
1 1 2 2 1 2
0 0 100 0 50 50

1.316987 1.816987 1.183013 1.683013 1.366025 1.633975

56.698730 25.000000 43.301270 25.000000 50.000000 13.397460

 


大白书上的例题,正好拿来测试模板。

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#define eps 1e-6
#define type double
using namespace std;

int sgn(double x){
    if(fabs(x)<eps) return 0;
    if(x<0) return -1;
    return 1;
}
struct vec{ //向量
    type x,y;
    vec(type xx=0,type yy=0):x(xx),y(yy){}
    bool operator==(vec a){
        return !sgn(x-a.x)&&!sgn(y-a.y);
    }
    vec operator*(type k){
        return vec(k*x,k*y);
    }
};
struct point{ //点
    type x,y;
    point(type xx=0,type yy=0):x(xx),y(yy){}
    vec operator-(point a){
        return vec(x-a.x,y-a.y);
    }
    point operator+(vec a){
        return point(x+a.x,y+a.y);
    }
    bool operator==(point a){
        return !sgn(x-a.x)&&!sgn(y-a.y);
    }
};
type dotp(vec a,vec b){ //点积a·b
    return a.x*b.x+a.y*b.y;
}
type crossp(vec a,vec b){ //叉积a×b
    return a.x*b.y-b.x*a.y;
}
double len(vec a){ //矢量a的模长
    return sqrt(a.x*a.x+a.y*a.y);
}
double rectify(double x){
    if(x>1) return 1;
    if(x<-1) return -1;
    return x;
}
double angle(vec a,vec b){
    return acos(rectify(dotp(a,b)/len(a)/len(b)));
}
point read_point(){
    point a;
    cin>>a.x;
    cin>>a.y;
    return a;
}
vec rotate(vec a,double r){
    return vec(a.x*cos(r)-a.y*sin(r),a.x*sin(r)+a.y*cos(r));
}
point line_ins(point a,vec v,point c,vec w){
    vec u=a-c;
    double t=crossp(w,u)/crossp(v,w);
    return a+v*t;
}
point get(point a,point b,point c){
    double r=angle(a-b,c-b);
    vec u=rotate(c-b,r/3);
    r=angle(a-c,b-c);
    vec v=rotate(b-c,-r/3);
    return line_ins(b,u,c,v);
}
int main()
{
    int t;
    point a,b,c,d,e,f;
    cin>>t;
    while(t--){
        a=read_point();
        b=read_point();
        c=read_point();
        d=get(a,b,c);
        e=get(b,c,a);
        f=get(c,a,b);
        printf("%.6f %.6f %.6f %.6f %.6f %.6f\n",d.x,d.y,e.x,e.y,f.x,f.y);
    }
	return 0;
}


你可能感兴趣的:(uva11178)