[Uva11178]Morley's Theorem(计算几何)

Description

题目链接

Solution

计算几何入门题

只要求出三角形DEF的一个点就能推出其他两个点

把一条边往内旋转a/3度得到一条射线,再做一条交点就是了

Code

#include <cstdio>
#include <algorithm>
#include <cmath>
#define db double
using namespace std;

struct Po{
	db x,y;
	Po(db x=0,db y=0):x(x),y(y){}
};
typedef Po Ve;

Ve operator - (Po A,Po B){return Ve(A.x-B.x,A.y-B.y);}
Ve operator + (Ve A,Ve B){return Ve(A.x+B.x,A.y+B.y);}
Ve operator * (Ve A,db p){return Ve(A.x*p,A.y*p);}
Ve operator / (Ve A,db p){return Ve(A.x/p,A.y/p);}

Po read_p(){
	Po res;
	scanf("%lf%lf",&res.x,&res.y);
	return res;
}

db Dot(Ve A,Ve B){return A.x*B.x+A.y*B.y;}
db Len(Ve A){return sqrt(Dot(A,A));}
db Angle(Ve A,Ve B){return acos(Dot(A,B)/Len(A)/Len(B));}

Ve Rotate(Ve A,db rad){
	return Ve(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}

db Corss(Ve A,Ve B){return A.x*B.y-A.y*B.x;}

Po GetIntersection(Po P,Ve v,Po Q,Ve w){
	Ve u=P-Q;
	db t=Corss(w,u)/Corss(v,w);
	return P+v*t;
}

Po getD(Po A,Po B,Po C){
	Ve v1=C-B;
	db a1=Angle(A-B,v1);
	v1=Rotate(v1,a1/3);
	
	Ve v2=B-C;
	db a2=Angle(A-C,v2);
	v2=Rotate(v2,-a2/3);//负数表示顺时针旋转 
	
	return GetIntersection(B,v1,C,v2);
}

void print(Po P){printf("%.6lf %.6lf ",P.x,P.y);}

int main(){
	int T;
	scanf("%d",&T);
	Po A,B,C,D,E,F; 
	while(T--){
		A=read_p();
		B=read_p();
		C=read_p();
		D=getD(A,B,C);
		E=getD(B,C,A);
		F=getD(C,A,B);
		print(D);print(E);print(F);puts("");
	}
	return 0;
}
posted @ 2018-03-12 20:46  void_f  阅读(130)  评论(0编辑  收藏  举报