uva11178

Problem D
Morley’s Theorem
Input: 
Standard Input

Output: Standard Output

 Morley’s theorem states that that the lines trisecting the angles of an arbitrary plane triangle meet at the vertices of an equilateral triangle. For example in the figure below the tri-sectors of angles A, B and C has intersected and created an equilateral triangle DEF.

 

Of course the theorem has various generalizations, in particular if all of the tri-sectors are intersected one obtains four other equilateral triangles. But in the original theorem only tri-sectors nearest to BC are allowed to intersect to get point D, tri-sectors nearest to CA are allowed to intersect point E and tri-sectors nearest to AB are intersected to get point F. Trisector like BD and CE are not allowed to intersect. So ultimately we get only one equilateral triangle DEF. Now your task is to find the Cartesian coordinates of D, E and F given the coordinates of A, B, and C.

 

Input

First line of the input file contains an integer N (0<N<5001) which denotes the number of test cases to follow. Each of the next lines contain sixintegers . This six integers actually indicates that the Cartesian coordinates of point A, B and C are  respectively. You can assume that the area of triangle ABC is not equal to zero,  and the points A, B and C are in counter clockwise order.

 
Output
For each line of input you should produce one line of output. This line contains six floating point numbers  separated by a single space. These six floating-point actually means that the Cartesian coordinates of D, E and F are  respectively. Errors less than   will be accepted.

 

Sample Input   Output for Sample Input

2
1 1 2 2 1 2
0 0 100 0 50 50

1.316987 1.816987 1.183013 1.683013 1.366025 1.633975

56.698730 25.000000 43.301270 25.000000 50.000000 13.397460

 


大白书上的例题,正好拿来测试模板。

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#define eps 1e-6
#define type double
using namespace std;

int sgn(double x){
    if(fabs(x)<eps) return 0;
    if(x<0) return -1;
    return 1;
}
struct vec{ //向量
    type x,y;
    vec(type xx=0,type yy=0):x(xx),y(yy){}
    bool operator==(vec a){
        return !sgn(x-a.x)&&!sgn(y-a.y);
    }
    vec operator*(type k){
        return vec(k*x,k*y);
    }
};
struct point{ //点
    type x,y;
    point(type xx=0,type yy=0):x(xx),y(yy){}
    vec operator-(point a){
        return vec(x-a.x,y-a.y);
    }
    point operator+(vec a){
        return point(x+a.x,y+a.y);
    }
    bool operator==(point a){
        return !sgn(x-a.x)&&!sgn(y-a.y);
    }
};
type dotp(vec a,vec b){ //点积a·b
    return a.x*b.x+a.y*b.y;
}
type crossp(vec a,vec b){ //叉积a×b
    return a.x*b.y-b.x*a.y;
}
double len(vec a){ //矢量a的模长
    return sqrt(a.x*a.x+a.y*a.y);
}
double rectify(double x){
    if(x>1) return 1;
    if(x<-1) return -1;
    return x;
}
double angle(vec a,vec b){
    return acos(rectify(dotp(a,b)/len(a)/len(b)));
}
point read_point(){
    point a;
    cin>>a.x;
    cin>>a.y;
    return a;
}
vec rotate(vec a,double r){
    return vec(a.x*cos(r)-a.y*sin(r),a.x*sin(r)+a.y*cos(r));
}
point line_ins(point a,vec v,point c,vec w){
    vec u=a-c;
    double t=crossp(w,u)/crossp(v,w);
    return a+v*t;
}
point get(point a,point b,point c){
    double r=angle(a-b,c-b);
    vec u=rotate(c-b,r/3);
    r=angle(a-c,b-c);
    vec v=rotate(b-c,-r/3);
    return line_ins(b,u,c,v);
}
int main()
{
    int t;
    point a,b,c,d,e,f;
    cin>>t;
    while(t--){
        a=read_point();
        b=read_point();
        c=read_point();
        d=get(a,b,c);
        e=get(b,c,a);
        f=get(c,a,b);
        printf("%.6f %.6f %.6f %.6f %.6f %.6f\n",d.x,d.y,e.x,e.y,f.x,f.y);
    }
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值