您的位置:首页 > 其它

Morley'’s Theorem 计算几何

2014-02-18 15:44 274 查看
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 six integers 

. 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

 

Problemsetters: Shahriar Manzoor
Special Thanks: Joachim Wulff

题意就是给了 A,B, C, 三个点,三角形的三等分角平分线会分别相交的点,可以拼成一个正三角形,求这个正三角形的三个顶点。
调试很久,终于调出来了~第一次觉得自己计算几何的代码不是那么丑!
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const double eps=1e-10;
double fabs(double x) { //取正
return x>0?x:-x;
}
int comp(double x){
if(fabs(x)<eps) return 0;
else return x>0?1:-1; //比大小
}
struct Point
{
double x,y;
Point(double x=0,double y=0):x(x),y(y) {} //赋值
void init(){
scanf("%lf%lf",&x,&y); //便捷的输入输出
}
void prif(){
printf("%.6lf %.6lf",x,y);
}

};

Point operator +(Point a,Point b){
return Point(a.x+b.x,a.y+b.y);
}

Point operator *(Point a,double tp){ //向量扩大倍数
return Point(a.x*tp,a.y*tp);
}

double dot(Point a,Point b){
return a.x*b.x+a.y*b.y;
}
double cross(Point a,Point b){
return a.x*b.y-a.y*b.x;
}
typedef Point Vector;
Vector rotate(Vector a,double du) //向量a 逆时针旋转 d° 得到的新向量
{
double x=a.x*cos(du)-a.y*sin(du);
double y=a.x*sin(du)+a.y*cos(du);
return Vector(x,y);
}
double LEN(Vector a){ // 计算|a|
return sqrt(a.x*a.x+a.y*a.y);
}
Vector operator -(Point a,Point b)
{
return Vector(a.x-b.x, a.y-b.y);
}

Point deal(Point a,Point b,Point c)
{
Vector bc,ba,bd,ca,cb,cd;
ba=a-b;
bc=c-b;
double len=LEN(bc)*LEN(ba);
double du=acos(dot(ba,bc)/len);
bd=rotate(bc,du/3.0);

ca=a-c;
cb=b-c;
len=LEN(cb)*LEN(ca);
du=acos(dot(cb,ca)/len);
cd= rotate(cb,du/3.0*(-1.0));

double tp=cross(cd,cb)/cross(bd,cd);
return b+ bd*tp;
}
int main()
{
//freopen("in.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
Point A,B,C;
Point ans[3];
A.init();B.init();C.init();
ans[0]=deal(A,B,C);
ans[1]=deal(B,C,A);
ans[2]=deal(C,A,B);
for(int i=0;i<3;i++)
{
ans[i].prif();
if(i!=2) printf(" ");
else printf("\n");
}

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  计算几何 math.h