• Morley's Therorem(UVA11178+几何)


     题意:Morley定理,求D、E、F的坐标

    思路:没什么算法,就是几何的应用。注意旋转角就好了。

    转载请注明出处:寻找&星空の孩子

     题目链接:UVA11178

     1 #include<cstdio>
     2 #include<cmath>
     3 #define PI acos(-1.0)
     4 using namespace std;
     5 
     6 struct Point
     7 {
     8     double x,y;
     9     Point(double x=0,double y=0):x(x),y(y){ }
    10  //   Point read_point() {scanf("%lf%lf",&this.x,&this.y);}
    11 };
    12 typedef Point Vector;
    13 Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
    14 Vector operator - (Point A,Point B)  {return Vector(A.x-B.x,A.y-B.y);}
    15 Vector operator * (Vector A,double p){return Vector(A.x*p,A.y*p);}
    16 Vector operator / (Vector A,double p){return Vector(A.x/p,A.y/p);}
    17 
    18 double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}
    19 double length(Vector A){return sqrt(Dot(A,A));}
    20 double Angle(Vector A,Vector B){return acos(Dot(A,B)/length(A)/length(B));}
    21 
    22 double Cross(Vector A,Vector B){return A.x*B.y-B.x*A.y;}
    23 
    24 Vector Rotate (Vector A,double rad)
    25 {
    26     //其中rad为逆时针旋转角
    27     return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
    28 }
    29 
    30 Point GetLineIntersection(Point P,Vector v,Point Q,Vector w)
    31 {
    32     Vector u=P-Q;
    33     if(Cross(v,w))
    34     {
    35         double t=Cross(w,u)/Cross(v,w);//精度高的时候,考虑自定义分数类
    36         return P+v*t;
    37     }
    38 //    else
    39  //       return ;
    40 }
    41 
    42 Point getD(Point A,Point B,Point C)
    43 {
    44     Vector v1=C-B;
    45     double a1=Angle(A-B,v1);
    46     v1=Rotate(v1,a1/3);
    47 
    48     Vector v2=B-C;
    49     double a2=Angle(A-C,v2);
    50     v2=Rotate(v2,-a2/3);//-表示顺时针旋转;
    51 
    52     return GetLineIntersection(B,v1,C,v2);
    53 
    54 }
    55 
    56 Point read_point(Point &P)
    57 {
    58     scanf("%lf%lf",&P.x,&P.y);
    59     return P;
    60 }
    61 int main()
    62 {
    63     int T;
    64     Point A,B,C,D,E,F;
    65     scanf("%d",&T);
    66     while(T--)
    67     {
    68         A=read_point(A);
    69         B=read_point(B);
    70         C=read_point(C);
    71 
    72 //        scanf("%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y);
    73 //        printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf
    ",A.x,A.y,B.x,B.y,C.x,C.y);
    74         D=getD(A,B,C);
    75         E=getD(B,C,A);
    76         F=getD(C,A,B);
    77         printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf
    ",D.x,D.y,E.x,E.y,F.x,F.y);
    78     }
    79     return 0;
    80 }
    View Code

     

     

  • 相关阅读:
    Eclipse常用插件汇总
    关于销售订单
    java下载文件的种方式
    左右对联
    链表
    Spring MVC 入门
    JAVA环境配置总结
    struts2 iterator判断奇偶
    保存页面的浏览记录
    心扬JS分页
  • 原文地址:https://www.cnblogs.com/yuyixingkong/p/4436328.html
Copyright © 2020-2023  润新知