美文网首页
Morley's Theorem

Morley's Theorem

作者: Gitfan | 来源:发表于2017-03-22 22:15 被阅读0次

    https://vjudge.net/problem/UVA-11178
    题目大意:给定一个三角形的三个顶点,求1/3角平分线的三个交点。

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<complex>
    using namespace std;
    struct Point
    {
        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);}
    bool operator <(const Point &a,const Point &b)
    {
        return a.x<b.x||(a.x==b.x&&a.y<b.y);
    }
    const double eps=1e-10;
    int dcmp(double x)
    {
        if(fabs(x)<eps) return 0;
        return x<0?-1:1;
    }
    bool operator ==(const Point &a,const Point &b)
    {
        return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0;
    }
    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;}
    double Area2(Point A,Point B,Point C){return cross(B-A,C-A);}
    Vector rorate(Vector A,double rad)
    {
        return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
    }
    Vector normal(Vector A)//左转90du,单位向量
    {
        double L=length(A);
        return Vector(-A.y/L,A.x/L);
    }
    Point getLineIntersection(Point P,Vector v,Point Q,Vector w)//两直线的交点
    {
        Vector u=P-Q;
        double t=cross(w,u)/cross(v,w);
        return P+v*t;
    }
    double distanceToLine(Point P,Point A,Point B)//点到直线距离
    {
        Vector v1=B-A,v2=P-A;
        return fabs(cross(v1,v2))/length(v1);
    }
    double distanceToSegment(Point p,Point A,Point B)
    {
        if(A==B) return length(p-A);
        Vector v1=B-A,v2=p-A,v3=p-B;
        if(dcmp(dot(v1,v2))<0) return length(v2);
        else if(dcmp(dot(v1,v3))>0) return length(v3);
        else return fabs(cross(v1,v2))/length(v1);
    }
    Point getLineProjection(Point P,Point A,Point B)//p点在AB直线上的投影
    {
        Vector v=B-A;
        return A+v*(dot(v,P-A)/dot(v,v));
    }
    bool segmentProperIntersection(Point a1,Point a2,Point b1,Point b2)
    {   //两直线是否规范相交:恰好有一个公共点并且公共点不在任何一条线段的端点
        double c1=cross(a2-a1,b1-a1),c2=cross(a2-a1,b2-a1),
               c3=cross(b2-b1,a1-b1),c4=cross(b2-b1,a2-b1);
               return dcmp(c1)*dcmp(c2)<0&&dcmp(c3)*dcmp(c4)<0;
    }
    bool onSegment(Point p,Point a1,Point a2)//p点是否在线段上,不包括a1,a2
    {
        return dcmp(cross(a1-p,a2-p))==0&&dcmp(dot(a1-p,a2-p))<0;
    }
    double convexPolygonArea(Point *arr,int n)//计算多边形面积
    {
        double area=0.0;
        for(int i=1;i<n-1;i++)
        {
            area+=cross(arr[i]-arr[0],arr[i+1]-arr[0]);
        }
        return fabs(area/2);
    
    }
    double PolygonArea(Point *arr,int n)//计算多边形有向面积
    {
        double area=0.0;
        for(int i=1;i<n-1;i++)
        {
            area+=cross(arr[i]-arr[0],arr[i+1]-arr[0]);
        }
        return area/2;
    
    }
    Point getD(Point A,Point B,Point C)
    {
        Vector v1=A-B,v2=C-B;
        double a1=angle(v1,v2);
        Vector v3=B-C,v4=A-C;
        double a2=angle(v3,v4);
        Vector l1=rorate(v2,a1/3.0),l2=rorate(v3,-a2/3.0);
        return getLineIntersection(B,l1,C,l2);
    
    }
    int main()
    {
       int t;
       scanf("%d",&t);
       Point A,B,C,D,E,F;
       while(t--)
       {
           scanf("%lf%lf",&A.x,&A.y);
           scanf("%lf%lf",&B.x,&B.y);
           scanf("%lf%lf",&C.x,&C.y);
           D=getD(A,B,C);
           E=getD(B,C,A);
           F=getD(C,A,B);
           printf("%.6f %.6f %.6f %.6f %.6f %.6f\n",D.x,D.y,E.x,E.y,F.x,F.y);
       }
    }
    

    相关文章

      网友评论

          本文标题:Morley's Theorem

          本文链接:https://www.haomeiwen.com/subject/mhuanttx.html