UVA11178 Morley's Theorem

UVA11178 Morley’s Theorem

题目大意:找到三角形Morley定理描述的等边三角形的三个顶点的坐标。

解题思路:给定三角形ABC,计算∠ABC,再通过BC向量旋转1/3∠ABC得到直线BD,同理求得CD,两直线交点是D点,同样可以求得E,F点。

求两向量夹角:

double angle(Vector a,Vector b){return acos( dot(a,b)/length(a)/length(b) );}

求向量旋转后得到的向量:

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 getIntersection(Point P,Vector v,Point Q,Vector w)
{
    Vector u=P-Q;
    double t=cross(w,u)/cross(v,w);
    return P+v*t;
}

有这些函数这道题直接模拟就好了。

#include <iostream>
#include <cmath>
#include <cstdio>

struct Point{
    double x,y;
    Point(double x,double y):x(x),y(y){}
    Point(){}
};
typedef Point Vector;
Vector operator+(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}
Vector operator-(Point a,Point b){return Vector(a.x-b.x,a.y-b.y);}
Vector operator*(Vector a,double D){return Vector(a.x*D,a.y*D);}
Vector operator/(Vector a,double D){return Vector(a.x/D,a.y/D);}
//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);
//}
const double eps=1e-10;
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) );}

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

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 getIntersection(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 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 fun(Point A,Point B,Point C)
{
    double angle_ABC=angle(A-B,C-B),angle_ACB=angle(A-C,B-C);
    Vector vector_BD=_rotate(C-B,angle_ABC/3),vector_CD=_rotate(B-C,-angle_ACB/3);
    Point D=getIntersection(B,vector_BD,C,vector_CD);
    D=getans(B,vector_BD,C,vector_CD);

    return D;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        double x[3],y[3];
        scanf("%lf%lf%lf%lf%lf%lf",x,y,x+1,y+1,x+2,y+2);
        Point A(x[0],y[0]),B(x[1],y[1]),C(x[2],y[2]);
        Point F=fun(C,A,B);
        Point D=fun(A,B,C);
        Point E=fun(B,C,A);

        printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\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、付费专栏及课程。

余额充值