題意: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\n",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\n",D.x,D.y,E.x,E.y,F.x,F.y); 78 } 79 return 0; 80 }