Morley's Theorem (简单几何)

Morleys theorem states that that the lines trisecting the angles of an arbitrary plane triangle meet at the vertices of an equi- lateral 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 gen-
eralizations, 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 inter- sected 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 six integers XA , YA , XB , YB , XC , YC . This six integers actually indicates that the Cartesian coordinates of point A, B and C are (XA,YA),(XB,YB) and (XC,YC) respectively. You can assume that the area of triangle ABC is not equal to zero, 0 ≤XA,YA,XB,YB,XC,YC ≤ 1000 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 XD , YD , XE , YE , XF , YF separated by a single space. These six floating-point actually means that the Cartesian coordinates of D, E and F are (XD , YD ),(XE , YE ) ,(XF , YF ) respectively. Errors less than 10−5 will be accepted.

Sample Input

2
112212
0 0 100 0 50 50

Sample Output

1.316987 1.816987 1.183013 1.683013 1.366025 1.633975
56.698730 25.000000 43.301270 25.000000 50.000000 13.397460

 已知ABC三点的坐标,求该三角形的三等分线的交点DEF的坐标

题解:简单几何问题,看代码,有注释

//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define lson l, mid, node<<1
#define rson mid + 1, r, node<<1|1
#define Root 1, m, 1
#define Node l, r, node
const int INF  =  0x3f3f3f3f;
const int O    =  1e6;
const int mod  =  20071027;
const int maxn =  2e5 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;


struct Point { double x, y; };

struct Line  { double k, b; };

double dis(double x1, double y1, double x2, double y2){ // 计算两点距离
    return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

double COS(double a, double b, double c) { // 计算cos值
    return (b * b + c * c - a * a ) / (2 * b * c);
}

Line getLine(double k1, double x0, double y0, double p){ // 经过x0,y0的且斜率为k1的的直线逆时针旋转p的角度
    double ag1 = atan(k1);
    double ag2 = ag1 + p;
    double k2 = tan(ag2);
    double b = y0 - k2 * x0;
    return {k2, b};
}

Point fun(Line L1, Line L2){ // 计算两线的交点
    double x0 = (L2.b - L1.b) / (L1.k - L2.k);
    double y0 = L1.k * x0 + L1.b;
    return {x0, y0};
}

Point getPoint(double x1, double y1, double cos1, double x2, double y2, double cos2){
    double k =  (y1 - y2) / (x1 - x2);
    double p1 = acos(cos1) / 3;
    double p2 = acos(cos2) / 3;
    Line L1 = getLine(k, x1, y1, p1);
    Line L2 = getLine(k, x2, y2, -p2);
    Point X = fun(L1, L2);
    return X;
}

int main(){
    int T; scanf("%d", &T);
    while( T -- ){
        double xa, xb, xc, ya, yb, yc;
        scanf("%lf%lf%lf%lf%lf%lf", &xa, &ya, &xb, &yb, &xc, &yc);
        double a = dis(xb, yb, xc, yc);
        double b = dis(xa, ya, xc, yc);
        double c = dis(xa, ya, xb, yb);
        double cosa = COS(a, b, c);
        double cosb = COS(b, a, c);
        double cosc = COS(c, a, b);
        Point D = getPoint(xb, yb, cosb, xc, yc, cosc);
        Point E = getPoint(xc, yc, cosc, xa, ya, cosa);
        Point F = getPoint(xa, ya, cosa, xb, yb, cosb);
        printf("%.6f %.6f %.6f %.6f %.6f %.6f\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、付费专栏及课程。

余额充值