zoukankan      html  css  js  c++  java
  • UVA 11178 Morley's Theorem(旋转+直线交点)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18543

    【思路】

           旋转+直线交点

           第一个计算几何题,照着书上代码打的。

    【代码】

     1 #include<cstdio>
     2 #include<cmath>
     3 #include<cstring>
     4 using namespace std;
     5 
     6 
     7 struct Pt { 
     8     double x,y;
     9     Pt(double x=0,double y=0):x(x),y(y) {}
    10 };
    11 typedef Pt vec;
    12 
    13 vec operator - (Pt A,Pt B) { return vec(A.x-B.x,A.y-B.y); }
    14 vec operator + (vec A,vec B) { return vec(A.x+B.x,A.y+B.y); }
    15 vec operator * (vec A,double p) { return vec(A.x*p , A.y*p); }
    16 
    17 double cross(vec A,vec B) { return A.x*B.y-A.y*B.x; }
    18 double Dot(vec A,vec B) { return A.x*B.x+A.y*B.y; }
    19 double Len(vec A) { return sqrt(Dot(A,A)); }
    20 double Angle(vec A,vec B) { return acos(Dot(A,B)/Len(A)/Len(B)); }
    21 
    22 vec rotate(vec A,double rad) { 
    23     return vec(A.x*cos(rad)-A.y*sin(rad) , A.x*sin(rad)+A.y*cos(rad));
    24 }
    25 Pt LineIntersection(Pt P,vec v,Pt Q,vec w) {
    26     vec u=P-Q;
    27     double t=cross(w,u)/cross(v,w);
    28     return P+v*t;
    29 }
    30 Pt getD(Pt A,Pt B,Pt C) {
    31     vec v1=C-B;
    32     double a=Angle(A-B,v1);
    33     v1=rotate(v1,a/3);
    34     vec v2=B-C;
    35     a=Angle(A-C,v2);
    36     v2=rotate(v2,-a/3);
    37     return LineIntersection(B,v1,C,v2);
    38 }
    39 Pt read() {
    40     double x,y;
    41     scanf("%lf%lf",&x,&y);
    42     return Pt(x,y);
    43 }
    44 int main() {
    45     Pt A,B,C,D,E,F;
    46     int T;
    47     scanf("%d",&T);
    48     while(T--) {
    49         A=read() , B=read() , C=read();
    50         D=getD(A,B,C);
    51         E=getD(B,C,A);
    52         F=getD(C,A,B);
    53         printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf
    ",D.x,D.y,E.x,E.y,F.x,F.y);
    54     }
    55     return 0;
    56 }
  • 相关阅读:
    FOJ2250 不可能弹幕结界
    寻找最大值
    Haybale Guessing
    MG loves string
    Curious Cupid
    Anton and Permutation
    TLE
    Jzzhu and Numbers
    Divisible Group Sums
    The merchant
  • 原文地址:https://www.cnblogs.com/lidaxin/p/5174413.html
Copyright © 2011-2022 走看看