zoukankan      html  css  js  c++  java
  • uva11178 Morley’s Theorem(求三角形的角三分线围成三角形的点)

    Morley’s Theorem Input: Standard Input

    Output: Standard Output

     Morley’s theorem states that that the lines trisecting the angles of an arbitrary plane triangle meet at the vertices of an equilateral triangle. For example in the figure below the tri-sectors of angles A, B and C has intersected and created an equilateral triangle DEF.

     

    Of course the theorem has various generalizations, in particular if all of the tri-sectors are intersected one obtains four other equilateral triangles. But in the original theorem only tri-sectors nearest to BC are allowed to intersect to get point D, tri-sectors nearest to CA are allowed to intersect point E and tri-sectors nearest to AB are intersected to get point F. Trisector like BD and CE are not allowed to intersect. So ultimately we get only one equilateral triangle DEF. Now your task is to find the Cartesian coordinates of D, E and F given the coordinates of A, B, and C.

     

    Input

    First line of the input file contains an integer N (0<N<5001) which denotes the number of test cases to follow. Each of the next lines contain sixintegers . This six integers actually indicates that the Cartesian coordinates of point A, B and C are  respectively. You can assume that the area of triangle ABC is not equal to zero,  and the points A, B and C are in counter clockwise order.

     

    Output

    For each line of input you should produce one line of output. This line contains six floating point numbers  separated by a single space. These six floating-point actually means that the Cartesian coordinates of D, E and F are  respectively. Errors less than   will be accepted.

     

    Sample Input   Output for Sample Input

    2
    1 1 2 2 1 2
    0 0 100 0 50 50

    1.316987 1.816987 1.183013 1.683013 1.366025 1.633975

    56.698730 25.000000 43.301270 25.000000 50.000000 13.397460

     

    tijie:

    tijie: 错的心酸。。。只需要求出两条直线求交点;

    代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 using namespace std;
     7 const double eps=1e-10;
     8 struct Point{
     9     double x,y;
    10     Point(double x=0,double y=0):x(x),y(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 bool operator < (const Point &a,const Point &b){
    18     return a.x<b.x||(a.x==b.x&&a.y<b.y);//排序 
    19 }
    20 int dcmp(double x){//
    21     if(fabs(x)<eps)return 0;
    22      return x<0?-1:1;
    23 }
    24 bool operator == (const Point &a,const Point &b){
    25     return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0;
    26 }
    27 double Dot(Vector A, Vector B) { return A.x * B.x + A.y * B.y; }  //点乘
    28 double Length(Vector A) { return sqrt(Dot(A, A)); } //向量的模
    29 double Angle(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); } //两个向量的夹角
    30 double Cross(Vector A, Vector B) { return A.x * B.y - A.y * B.x; } //叉乘
    31 double Area(Point A, Point B, Point C) { return Cross(B - A, C - A); } //三个点组成的三角形的面积
    32 
    33 Vector Rotate(Vector A, double rad) { //向量A逆时针旋转rad弧度后的坐标
    34     return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));
    35 }
    36 
    37 Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) {
    38     Vector u = P - Q;
    39     double t = Cross(w, u) / Cross(v, w);
    40     return P + v * t;
    41 }
    42 Point getD(Point A,Point B,Point C){
    43     Vector v1=C-B;
    44     double a1=Angle(A-B,v1);
    45     v1=Rotate(v1,a1/3);//少了ROTATE。。。。。。 
    46     Vector v2=B-C;
    47     double a2=Angle(A-C,v2);
    48     v2=Rotate(v2,-a2/3);
    49     //printf("%lf %lf %lf %lf %lf %lf
    ",v1.x,v1.y,v2.x,v2.y,a1/3,a2/3);
    50     return GetLineIntersection(B,v1,C,v2);
    51 } 
    52 int main(){
    53     int T;
    54     Point a,b,c,d,e,f;
    55     scanf("%d",&T);
    56     while(T--){
    57         scanf("%lf%lf%lf%lf%lf%lf",&a.x, &a.y, &b.x, &b.y, &c.x, &c.y);
    58         d=getD(a,b,c);
    59         e=getD(b,c,a);
    60         f=getD(c,a,b);
    61          printf("%lf %lf %lf %lf %lf %lf
    ",d.x,d.y,e.x,e.y,f.x,f.y); 
    62     }
    63     return 0;
    64 }
  • 相关阅读:
    2020-2021-1 20201217《信息安全专业导论》第十一周学习总结
    python模拟进程状态
    博客文章汇总
    20201225 张晓平《信息安全专业导论》第十三周学习总结
    网站设计
    gpg
    20201225 张晓平《信息安全专业导论》第十二周学习总结
    wire shark
    ssh
    成绩调节
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4937677.html
Copyright © 2011-2022 走看看