UVA 11178 Morley's Theorem 计算几何

题目的链接如下:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2119
题目的VJ链接如下:
http://acm.hust.edu.cn/vjudge/problem/18543

题目格式是PDF的而且有图形,就不在这里说了,把题目的大意说一下,就是他给你一个定理叫做 Morley定理,任意三角形的三个角的6条三等分线会交出一个等边三角形记作△DEF,那么现在给出△ABC的三个顶点,请计算D、E、F的坐标.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;

struct point{
   // public:
        double x, y;
        point(double x = 0 , double y = 0):x(x), y(y){};
};
typedef point Vector;
Vector operator + (Vector A, Vector B){return Vector(A.x+B.x, A.y+B.y);}
Vector operator - (Vector A, Vector B){return Vector(A.x-B.x, A.y-B.y);}
Vector operator * (Vector A, double p){return Vector(A.x*p, A.y*p);}
Vector operator / (Vector A, double p){return Vector(A.x/p, A.y/p);}
double cross(Vector A, Vector B){//叉积
    return A.x * B.y - A.y * B.x;
}
point get_line(point P, Vector v, point Q, Vector w)//直线的表达方式,参数法
{
    Vector u = P-Q;
    double t = cross(w,u)/cross(v,w);
    return P+v*t;
}

Vector Rotate(Vector A, double rad)//向量旋转(逆时针为正角)
{
    return Vector (A.x*cos(rad) - A.y*sin(rad), A.x*sin(rad) + A.y*cos(rad));
}

double dot(Vector A, Vector B){return A.x*B.x + A.y*B.y;}//点乘
double length(Vector A){return sqrt(dot(A,A));}//向量的长度
double angle(Vector A, Vector B){return acos(dot(A,B)/length(A)/length(B));}//两个向量之间的夹角
point get_ans(point A, point B, point C){
    Vector v1 = C - B;
    double a1 = angle(A-B, v1);
    v1 = Rotate(v1, a1/3);
    Vector v2 = B - C ;
    double a2 = angle(A-C, v2);
    v2 = Rotate(v2, -a2/3);
    return get_line(B, v1, C, v2);
}

int main()
{
    point D, E, F;
    point A, B, C;
    int n,t ;
    cin >> t;
    while(t--){
        //cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y;
        scanf("%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y);
        D = get_ans(A,B,C);
        E = get_ans(B,C,A);
        F = get_ans(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;
}
/*测试数据
2
1 1 2 2 1 2
*/
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值