UVAOJ 11178——Morley’s Theorem

这是一道计算几何的模板题,求点D的时候,就把角ABC求出来,然后除以三,然后把BC边旋转一下,同理求出BCA的度数,然后除以三,再把CB旋转一下,两个旋转以后的交点就是D。用同样的方法求出E和F。

代码如下:

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
struct point{
	double x,y;
	point (double x=0,double y=0):x(x),y(y){ }
};

typedef point vector;

vector operator +(vector A,vector 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);}

bool operator <(const point& a,const point &b){
	return a.x<b.x||(a.x==b.x&&a.y<b.y);
}

bool operator ==(const point &a,const point &b){
	return (a.x==b.x)&&(a.y==b.y);
}

double dot(vector a,vector b){
	return a.x*b.x+a.y*b.y;
}

double lenth(vector a){
	return sqrt(dot(a,a));
}

double cross(vector a,vector b){
	return a.x*b.y-a.y*b.x;
}

double angle(vector a,vector b){
	return acos(dot(a,b)/lenth(a)/lenth(b));
}

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

point getlineintersection(point p,vector v,point q,vector w){
	vector u=p-q;
	double t=cross(w,u)/cross(v,w);
	return p+v*t;
}

int main(){
	ios::sync_with_stdio(false);
//	freopen("data.txt","r",stdin);
	int n;
	cin>>n;
	while(n--){
		point A,B,C;
		cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y;
		point D;
		double ABC=angle((A-B),C-B);
		ABC/=3;
		vector BD=rotate(C-B,ABC);
		double BCA=angle(A-C,B-C);
		BCA/=3;
		vector CD=rotate(B-C,-BCA);
		D=getlineintersection(B,BD,C,CD);
		point F;
		vector BF=rotate(BD,ABC);
		double BAC=angle(B-A,C-A);
		BAC/=3;
		vector AF=rotate(B-A,BAC);
		F=getlineintersection(A,AF,B,BF);
		vector AE=rotate(AF,BAC);
		vector CE=rotate(A-C,BCA);
		point E=getlineintersection(A,AE,C,CE);
		cout<<setiosflags(ios::fixed)<<setprecision(6)<<D.x<<' '<<D.y<<' '<<E.x<<' '<<E.y<<' '<<F.x<<' '<<F.y<<endl;
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值