您的位置:首页 > 其它

UVA 11178 || Morley's Theorem (向量旋转求交点

2015-02-06 12:05 429 查看


给出A B C 坐标,做三角形的三等分线,求交点D E F的坐标。

将 BC向量,与CB向量分别旋转1/3的角度,求到交点。

大白书上的原题。

代码标准参考大白。

/*几何模版*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

struct point
{
double x,y,d;
point(double a,double b):x(a),y(b){}
point(){}
};
typedef point vec;

//向量+向量=向量, 点  +向量=点
vec operator +  ( vec a,   vec b)      {  return vec(a.x+b.x,a.y+b.y);}

vec operator -  ( point a, point b)    {  return vec(a.x-b.x,a.y-b.y);}

vec operator *  ( vec a,   double p)   {  return vec(a.x*p,a.y*p);}

vec operator /  ( vec a,   double p)   {  return vec(a.x/p,a.y/p);}

const double eps =1e-10;

// 点积(向量 a,向量 b)
double dot( vec a,vec b)    {   return a.x*b.x + a.y*b.y;}

double length( vec a)       {   return sqrt(dot(a,a) );}

//向量 a,b 的夹角
double angle(vec a,vec b)
{
return acos(    dot(a,b)/length(a)/length(b)    );
}

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

// 向量 a 旋转 rad 弧度
vec rotat(vec a,double rad)
{
return vec( a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}

//两条直线 p+tv 和 q + tw 有唯一交点,当且仅当 cross(v,w)!=0
point getlinetnersection(point p,vec v,point q,vec w)
{
vec u = p-q;
double t = cross(w,u) /cross(v,w);
return p + v*t;
}

point getpoint( point a,point b,point c)
{
vec v1 = c- b;
double a1 = angle(a-b,v1);
v1 = rotat(v1,a1/3.0);

vec v2 = b-c;
double a2 = angle( a-c,v2);
v2 = rotat(v2,-a2/3.0);//负数表示顺时针玄真

return getlinetnersection(b,v1,c,v2);
}
int main()
{
int t;
cin>>t;
while( t-- )
{
point a,b,c,d,e,f;
int k = 3;
scanf("%lf %lf %lf %lf %lf %lf",
&a.x,&a.y,&b.x,&b.y,&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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: