您的位置:首页 > 其它

uva11178 Morley's Theorem

2017-02-24 21:03 260 查看
Morleys theorem states that that the lines trisecting the angles of an

arbitrary plane triangle meet at the vertices of an equi- lateral

triangle. For example in the gure below the tri-sectors of angles A,

B and C has intersected and created an equilateral triangle DEF. Of

course the theorem has various gen- eralizations, 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 inter-

sected 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 nd the Cartesian coordinates of D, E and F given the

coordinates of A, B, and C. Input First line of the input le contains

an integer N (0 < N< 5001) which denotes the number of test cases to

follow. Each of the next lines contain six integers X A ;Y A ;X B ;Y

B ;X C ;Y C . This six integers actually indicates that the Cartesian

coordinates of point A, B and C are ( X A ;Y A ),( X B ;Y B ) and ( X

C ;Y C ) respectively. You can assume that the area of triangle ABC is

not equal to zero, 0  X A ;Y A ;X B ;Y B ;X C ;Y C  1000 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 oating point numbers X D ;Y D ;X E ;Y E ;X F ;Y F separated by a

single space. These six oating-point actually means that the

Cartesian coordinates of D, E and F are ( X D ;Y D ),( X E ;Y E ) ,( X

F ;Y F ) respectively. Errors less than 10

算出来两边夹角,把其中一边旋转夹角的三分之一,再求两条直线交点。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
struct v
{
double x,y;
void rd()
{
scanf("%lf%lf",&x,&y);
}
void out()
{
printf("%.6f %.6f ",x,y);
}
v operator + (const v &v1)
{
return (v){x+v1.x,y+v1.y};
}
v operator - (const v &v1)
{
return (v){x-v1.x,y-v1.y};
}
v operator * (const double &k)
{
return (v){k*x,k*y};
}
v operator / (const double &k)
{
return (v){x/k,y/k};
}
}a,b,c;
double dot(v v1,v v2)
{
return v1.x*v2.x+v1.y*v2.y;
}
double cross(v v1,v v2)
{
return v1.x*v2.y-v1.y*v2.x;
}
double len(v v1)
{
return sqrt(dot(v1,v1));
}
double angle(v v1,v v2)
{
return acos(dot(v1,v2)/len(v1)/len(v2));
}
v rot(v v1,double x)
{
return (v){v1.x*cos(x)-v1.y*sin(x),v1.x*sin(x)+v1.y*cos(x)};
}
struct line
{
v p,a;
};
v intersec(line l1,line l2)
{
v v1=l1.p-l2.p;
double t=cross(l2.a,v1)/cross(l1.a,l2.a);
return l1.p+l1.a*t;
}
v solve(v a,v b,v c)
{
double a1=angle(a-c,b-c),a2=angle(c-b,a-b);
line l1=(line){c,rot(b-c,-a1/3)},l2=(line){b,rot(c-b,a2/3)};
return intersec(l1,l2);
}
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
a.rd();
b.rd();
c.rd();
solve(a,b,c).out();
solve(b,c,a).out();
solve(c,a,b).out();
putchar('\n');
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  计算几何