UVA 11178 - Morley's Theorem 向量

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;
}


你可能感兴趣的:(编程,数学,ACM,几何)