UVa 11178 (简单练习) Morley's Theorem

题意:

Morley定理:任意三角形中,每个角的三等分线,相交出来的三个点构成一个正三角形。

不过这和题目关系不大,题目所求是正三角形的三个点的坐标,保留6位小数。

分析:

由于对称性,求出D点,EF也是同样的。

用点和向量的形式表示一条直线,向量BA、BC的夹角为a1,则将BC逆时针旋转a1/3可求得 直线BD,同理也可求得直线CD,最后再求交点即可。

 

  1 //#define LOCAL
  2 #include <cstdio>
  3 #include <cstring>
  4 #include <algorithm>
  5 #include <cmath>
  6 using namespace std;
  7 
  8 struct Point
  9 {
 10     double x, y;
 11     Point(double x=0, double y=0) :x(x),y(y) {}
 12 };
 13 typedef Point Vector;
 14 const double EPS = 1e-10;
 15 
 16 Vector operator + (Vector A, Vector B)    { return Vector(A.x + B.x, A.y + B.y); }
 17 
 18 Vector operator - (Vector A, Vector B)    { return Vector(A.x - B.x, A.y - B.y); }
 19 
 20 Vector operator * (Vector A, double p)    { return Vector(A.x*p, A.y*p); }
 21 
 22 Vector operator / (Vector A, double p)    { return Vector(A.x/p, A.y/p); }
 23 
 24 bool operator < (const Point& a, const Point& b)
 25 { return a.x < b.x || (a.x == b.x && a.y < b.y); }
 26 
 27 int dcmp(double x)
 28 { if(fabs(x) < EPS) return 0; else x < 0 ? -1 : 1; }
 29 
 30 bool operator == (const Point& a, const Point& b)
 31 { return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0; }
 32 
 33 double Dot(Vector A, Vector B)
 34 { return A.x*B.x + A.y*B.y; }
 35 
 36 double Length(Vector A)    { return sqrt(Dot(A, A)); }
 37 
 38 double Angle(Vector A, Vector B)
 39 { return acos(Dot(A, B) / Length(A) / Length(B)); }
 40 
 41 double Cross(Vector A, Vector B)
 42 { return A.x*B.y - A.y*B.x; }
 43 
 44 double Area2(Point A, Point B, Point C)
 45 { return Cross(B-A, C-A); }
 46 
 47 Vector VRotate(Vector A, double rad)
 48 {
 49     return Vector(A.x*cos(rad) - A.y*sin(rad), A.x*sin(rad) + A.y*cos(rad));
 50 }
 51 
 52 Point GetLineIntersection(Point P, Vector v, Point Q, Vector w)
 53 {
 54     Vector u = P - Q;
 55     double t = Cross(w, u) / Cross(v, w);
 56     return P + v*t;
 57 }
 58 
 59 Point read_point(void)
 60 {
 61     double x, y;
 62     scanf("%lf%lf", &x, &y);
 63     return Point(x, y);
 64 }
 65 
 66 Point GetD(Point A, Point B, Point C)
 67 {
 68     Vector v1 = C - B;
 69     double a1 = Angle(A-B, v1);
 70     v1 = VRotate(v1, a1/3);
 71 
 72     Vector v2 = B - C;
 73     double a2 = Angle(A-C, v2);
 74     v2 = VRotate(v2, -a2/3);
 75 
 76     return GetLineIntersection(B, v1, C, v2);
 77 }
 78 
 79 int main(void)
 80 {
 81     #ifdef    LOCAL
 82         freopen("11178in.txt", "r", stdin);
 83     #endif
 84     
 85     int T;
 86     scanf("%d", &T);
 87     while(T--)
 88     {
 89         Point A, B, C, D, E, F;
 90         A = read_point();
 91         B = read_point();
 92         C = read_point();
 93         D = GetD(A, B, C);
 94         E = GetD(B, C, A);
 95         F = GetD(C, A, B);
 96         printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n", D.x, D.y, E.x, E.y, F.x, F.y);
 97     }
 98 
 99     return 0;
100 }
代码君

 

posted @ 2014-10-13 16:42  AOQNRMGYXLMV  阅读(178)  评论(0编辑  收藏  举报