您的位置:首页 > 其它

UVa11178 - Morley's Theorem(向量旋转+直线交点)

2017-10-16 15:42 363 查看
题目链接

简介:三角形内角三等分线相交形成等边三角形

分析:

向量旋转和直线交点的练习

tip

新操作的第一次练习,板子不要写错

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>

using namespace std;

struct node{
double x,y;
node (double xx=0,double yy=0)
{
x=xx;y=yy;
}
};

node operator + (const node &a,const node &b){return node(a.x+b.x,a.y+b.y);}
node operator - (const node &a,const node &b){return node(a.x-b.x,a.y-b.y);}
node operator * (const node &a,const double &b){return node(a.x*b,a.y*b);}
node operator / (const node &a,const double &b){return node(a.x/b,a.y/b);}

double Dot(node x,node y){return x.x*y.x+x.y*y.y;}
double Len(node x){return sqrt(Dot(x,x));}
double Angle(node x,node y){
return acos( Dot(x,y)/Len(x)/Len(y) );
}

double Cross(node x,node y){return x.x*y.y-x.y*y.x;}

node rotate(node x,double a)
{
return node(x.x*cos(a)-x.y*sin(a),x.x*sin(a)+x.y*cos(a));
}

node getpoint(node P,node v,node Q,node w)
{
node u=P-Q;
double t=Cross(w,u)/Cross(v,w);
return P+v*t;
}

node get(node A,node B,node C)
{
node X=C-B;
double a=Angle(A-B,X);
X=rotate(X,a/3);

node Y=B-C;
double b=Angle(A-C,Y);
Y=rotate(Y,-b/3);      //负数表示顺时针转动

return getpoint(B,X,C,Y);
}

int main()
{
node A,B,C,D,E,F;
int T;
scanf("%d",&T);
while (T--)
{
scanf("%lf %lf",&A.x,&A.y);
scanf("%lf %lf",&B.x,&B.y);
scanf("%lf %lf",&C.x,&C.y);
D=get(A,B,C);
E=get(B,C,A);
F=get(C,A,B);
printf("%0.6lf %0.6lf %0.6lf %0.6lf %0.6lf %0.6lf\n",D.x,D.y,E.x,E.y,F.x,F.y);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: