题意:Morley定理,求D、E、F的坐标
思路:没什么算法,就是几何的应用。注意旋转角就好了。
转载请注明出处:寻找&星空の孩子
题目链接:UVA11178
#include<cstdio> #include<cmath> #define PI acos(-1.0) using namespace std; struct Point { double x,y; Point(double x=0,double y=0):x(x),y(y){ } // Point read_point() {scanf("%lf%lf",&this.x,&this.y);} }; 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 p){return Vector(A.x*p,A.y*p);} Vector operator / (Vector A,double p){return Vector(A.x/p,A.y/p);} 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-B.x*A.y;} Vector Rotate (Vector A,double rad) { //其中rad为逆时针旋转角 return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad)); } Point GetLineIntersection(Point P,Vector v,Point Q,Vector w) { Vector u=P-Q; if(Cross(v,w)) { double t=Cross(w,u)/Cross(v,w);//精度高的时候,考虑自定义分数类 return P+v*t; } // else // return ; } Point getD(Point A,Point B,Point C) { Vector v1=C-B; double a1=Angle(A-B,v1); v1=Rotate(v1,a1/3); Vector v2=B-C; double a2=Angle(A-C,v2); v2=Rotate(v2,-a2/3);//-表示顺时针旋转; return GetLineIntersection(B,v1,C,v2); } Point read_point(Point &P) { scanf("%lf%lf",&P.x,&P.y); return P; } int main() { int T; Point A,B,C,D,E,F; scanf("%d",&T); while(T--) { A=read_point(A); B=read_point(B); C=read_point(C); // scanf("%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y); // printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n",A.x,A.y,B.x,B.y,C.x,C.y); D=getD(A,B,C); E=getD(B,C,A); F=getD(C,A,B); printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n",D.x,D.y,E.x,E.y,F.x,F.y); } return 0; }
时间: 2024-10-21 15:44:32