• [Uva11178]Morley's Theorem(计算几何)


    Description

    题目链接

    Solution

    计算几何入门题

    只要求出三角形DEF的一个点就能推出其他两个点

    把一条边往内旋转a/3度得到一条射线,再做一条交点就是了

    Code

    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #define db double
    using namespace std;
    
    struct Po{
    	db x,y;
    	Po(db x=0,db y=0):x(x),y(y){}
    };
    typedef Po Ve;
    
    Ve operator - (Po A,Po B){return Ve(A.x-B.x,A.y-B.y);}
    Ve operator + (Ve A,Ve B){return Ve(A.x+B.x,A.y+B.y);}
    Ve operator * (Ve A,db p){return Ve(A.x*p,A.y*p);}
    Ve operator / (Ve A,db p){return Ve(A.x/p,A.y/p);}
    
    Po read_p(){
    	Po res;
    	scanf("%lf%lf",&res.x,&res.y);
    	return res;
    }
    
    db Dot(Ve A,Ve B){return A.x*B.x+A.y*B.y;}
    db Len(Ve A){return sqrt(Dot(A,A));}
    db Angle(Ve A,Ve B){return acos(Dot(A,B)/Len(A)/Len(B));}
    
    Ve Rotate(Ve A,db rad){
    	return Ve(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
    }
    
    db Corss(Ve A,Ve B){return A.x*B.y-A.y*B.x;}
    
    Po GetIntersection(Po P,Ve v,Po Q,Ve w){
    	Ve u=P-Q;
    	db t=Corss(w,u)/Corss(v,w);
    	return P+v*t;
    }
    
    Po getD(Po A,Po B,Po C){
    	Ve v1=C-B;
    	db a1=Angle(A-B,v1);
    	v1=Rotate(v1,a1/3);
    	
    	Ve v2=B-C;
    	db a2=Angle(A-C,v2);
    	v2=Rotate(v2,-a2/3);//负数表示顺时针旋转 
    	
    	return GetIntersection(B,v1,C,v2);
    }
    
    void print(Po P){printf("%.6lf %.6lf ",P.x,P.y);}
    
    int main(){
    	int T;
    	scanf("%d",&T);
    	Po A,B,C,D,E,F; 
    	while(T--){
    		A=read_p();
    		B=read_p();
    		C=read_p();
    		D=getD(A,B,C);
    		E=getD(B,C,A);
    		F=getD(C,A,B);
    		print(D);print(E);print(F);puts("");
    	}
    	return 0;
    }
    
  • 相关阅读:
    HDU 1232 畅通工程(并查集分析)
    NYOJ 2 括号配对问题
    HDU 1205 吃糖果
    HDU 1201 18岁生日
    [ACM] hdu Find a way
    [ACM] hdu Ignatius and the Princess I

    pongo(英雄会)编程挑战: 人人code,整数取反
    [ACM] POJ 1852 Ants
    波司登杯2013微软office应用创意大赛烟台大学校园赛参赛历程
  • 原文地址:https://www.cnblogs.com/void-f/p/8551859.html
Copyright © 2020-2023  润新知