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 |
题目大意:
Morley定理是这样的:作三角形ABC每个内角的三等分线,相交成三角形DEF,则DEF是等边三角形,如果所示,你的任务是根据A、B、C三个点的位置确定D、E、F三个点的位置。
分析:
考虑到对称性,只需要直到如何求D点即可。首先需要计算角ABC的值a,然后把射线BC逆时针旋转a/3.得到直线BD,同理可以得到直线CD,求交点即可。
代码如下:
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
struct Point
{
double x,y;
Point(double x = 0,double y = 0):x(x),y(y) {}
};
typedef Point Vector;
Vector operator - (Point A,Point 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);
}
Vector Rotate(Vector A,double rad) //旋转
{
return Vector(A.x * cos(rad) - A.y * sin(rad),A.x * sin(rad) + A.y * cos(rad));
}
double Dot(Vector A,Vector B) //点积
{
return A.x * B.x + A.y * B.y;
}
double Length(Vector A) //线段长度
{
return sqrt(Dot(A,A));
}
double Cross(Vector A,Vector B) //叉积
{
return A.x * B.y - A.y * B.x;
}
Point GetLineIntersection(Point P,Vector v,Point Q,Vector w) //直线交点公式
{
Vector u = P - Q; //向量QP
double t = Cross(w,u) / Cross(v,w);
return P + v*t;
}
double Angle(Vector A,Vector B) //求角度
{
return acos(Dot(A,B) / Length(A) / Length(B));
}
Point getD(Point A,Point B,Point C) //得到交点
{
Vector v1 = C - B; //得到向量BC
double a1 = Angle(A-B,v1); //得到直线AB和BC之间的夹角
v1 = Rotate(v1,a1/3); //逆时针旋转a1/3
Vector v2 = B - C; //得到向量CB
double a2 = Angle(A-C,v2);
v2 = Rotate(v2,-a2/3); //顺时针旋转a2/3
return GetLineIntersection(B,v1,C,v2);
}
int main()
{
int T;
Point A,B,C,D,E,F;
double num1,num2,num3,num4,num5,num6;
cin>>T;
while(T--)
{
cin>>num1>>num2>>num3>>num4>>num5>>num6;
A.x = num1,A.y = num2;
B.x = num3,B.y = num4;
C.x = num5,C.y = num6;
D = getD(A,B,C);
E = getD(B,C,A);
F = getD(C,A,B);
printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n",D.x,D.y,E.x,E.y,F.x,F.y);
}
return 0;
}
运行截图: