UVA 11178 - Morley's Theorem 向量

58 篇文章 0 订阅
7 篇文章 0 订阅

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2119

题目大意:

Morley定理是这样定义的,做三角形ABC每个内角的三等分线,相交成三角形DEF,则DEF是等边三角形。如图,你的任务是根据A,B,C三个点的位置确定D、E、F的位置。

思路:

把BC边旋转三分之一的角ABC,CB边旋转三分之一的角ACB,然后求交点D就出来了。其他的同理。

PS:作者的向量类写得不错,嗯,等我回学校了要把c++ primer plus里的向量模版好好看看

#include<cstdio>
#include<cmath>

struct point
{
	double x,y;
	point(double x=0,double y=0): x(x),y(y){}
};
typedef point Vector;
Vector operator +(point a,point b)
{
	return Vector(a.x+b.x,a.y+b.y);
}
Vector operator *(point a,double b)
{
	return Vector(a.x*b,a.y*b);
}
Vector operator -(point a,point b)
{
	return Vector(a.x-b.x,a.y-b.y);
}

double dot(Vector a,Vector b)
{
	return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b)
{
	return a.x*b.y-a.y*b.x;
}
double len(Vector a)
{
	return sqrt(a.x*a.x+a.y*a.y);
}
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 getans(point p,Vector v,point q,Vector w){
	Vector u= p-q;
	double t=cross(w,u) / cross(v,w);
	return p+v*t;
}
point getPoint(point a,point b,point c)
{
	Vector bc=c-b;
	Vector ba=a-b;
	double x=acos(  dot(ba,bc) / len(bc) / len(ba) );
	Vector bd= rotate(bc,x/3);

	Vector ca=a-c;
	Vector cb=b-c;
	x=acos(  dot(cb,ca) / len(cb) / len(ca) );
	Vector cd=rotate(cb,-x/3);

	return getans(b,bd,c,cd);
}
int main()
{
	int T;
	scanf("%d",&T);
	point a,b,c,d,e,f;
	while(T--)
	{		
		scanf("%lf%lf",&a.x,&a.y);
		scanf("%lf%lf",&b.x,&b.y);
		scanf("%lf%lf",&c.x,&c.y);
		d=getPoint(a,b,c);
		e=getPoint(b,c,a);
		f=getPoint(c,a,b);
		printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n",d.x,d.y,e.x,e.y,f.x,f.y);
	}
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值