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

 


考虑到对称性,只需要知道如何求D点就行了。首先需要知道 /_ABC的值a,然后把射线BC逆时针旋转a/3,得到直线BD。同理可以得到直线CD,求交点就行

#include <iostream>
#include <complex>
#include <iomanip>
#include <math.h>
#include <algorithm>
using namespace std;
struct Point
{
    double x,y;
    Point(){}
    Point(double x,double y):x(x),y(y){}
};
Point operator+(Point A,Point B)//操作符运算
{
    return Point(A.x+B.x,A.y+B.y);
}
Point operator-(Point A,Point B)
{
    return Point(A.x-B.x,A.y-B.y);
}
Point operator*(Point A,double p)
{
    return Point(A.x*p,A.y*p);
}


double Dot(Point A,Point B)//两个向量的点积
{
    return A.x*B.x+A.y*B.y;
}
double Length(Point A)//一个向量的长度
{
    return sqrt(Dot(A,A));
}
double Angle(Point A,Point B)//求两个向量的夹角
{
    return acos(Dot(A,B)/Length(A)/Length(B));
}
double Cross(Point A,Point B)//求两个向量的叉积
{
    return A.x*B.y-A.y*B.x;
}
Point Rotate(Point A,double rad)//向量旋转
{
    return Point(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
Point GetLineIntersection(Point P,Point v,Point Q,Point w)//求直线的交点
{
    Point u=P-Q;
    double t=Cross(w,u)/Cross(v,w);
    return P+v*t;
}
Point get(Point A,Point B,Point C)
{
    Point v1=C-B;//求直线BD
    double a1=Angle(A-B,v1);
    v1=Rotate(v1,a1/3);


    Point v2=B-C;//求直线CD
    double a2=Angle(A-C,v2);
    v2=Rotate(v2,-a2/3);//负数表示顺时针


    return GetLineIntersection(B,v1,C,v2);//求两线交点
}
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        Point A,B,C;
        Point D,E,F;
        cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y;
        D=get(A,B,C);
        E=get(B,C,A);
        F=get(C,A,B);
        cout<<setiosflags(ios::fixed)<<setprecision(6);
        cout<<D.x<<" "<<D.y<<" "<<E.x<<" "<<E.y<<" "<<F.x<<" "<<F.y<<endl;
    }
    return 0;
}






posted on 2015-04-25 18:41  星斗万千  阅读(159)  评论(0编辑  收藏  举报