• Morley's Theorem (计算几何基础+向量点积、叉积、旋转、夹角等+两直线的交点)


    题目链接https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2119

    题面:Morleys 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 trisectors 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 six integers XA,YA,XB,YB,XC,YC. This six integers actually indicates that the Cartesian coordinates of point A, B and C are (XA,YA),(XB,YB) and (XC,YC) respectively. You can assume that the area of triangle ABC is not equal to zero, 0 ≤ XA,YA,XB,YB,XC,YC ≤ 1000 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 XD,YD,XE,YE,XF,YF separated by a single space. These six floating-point actually means that the Cartesian coordinates of D, E and F are (XD,YD),(XE,YE) ,(XF,YF) respectively. Errors less than 10−5 will be accepted.
    Sample Input
    2

    1 1 2 2 1 2

    0 0 100 0 50 50
    Sample Output
    1.316987 1.816987 1.183013 1.683013 1.366025 1.633975

    56.698730 25.000000 43.301270 25.000000 50.000000 13.397460

    思路:本题为一道比较简单的计算几何入门题,运用了很多的计算几何知识,不过只要想通如何求DEF的话,就只需通过套用模板即可解决

    代码实现如下:

     1 #include <cstdio>
     2 #include <cmath>
     3 using namespace std;
     4 
     5 struct Point{
     6     double x,y;
     7     Point(double x = 0, double y = 0) : x(x), y(y) {}
     8 };
     9 
    10 typedef Point Vector;
    11 
    12 int t;
    13 Point A, B, C, D, E, F;
    14 
    15 Vector operator + (Vector A, Vector B){
    16     return Vector(A.x + B.x, A.y + B.y);
    17 }
    18 
    19 Vector operator - (Vector A, Vector B){
    20     return Vector(A.x - B.x, A.y - B.y);
    21 }
    22 
    23 Vector operator * (Vector A, double p){
    24     return Vector(A.x * p, A.y * p);
    25 }
    26 
    27 Vector operator / (Vector A, double p){
    28     return Vector(A.x / p, A.y / p);
    29 }
    30 
    31 double Dot(Vector A, Vector B){
    32     return A.x * B.x + A.y * B.y;
    33 }
    34 
    35 double Length(Vector A){
    36     return sqrt(Dot(A, A));
    37 }
    38 
    39 double Angle(Vector A, Vector B){
    40     return acos(Dot(A, B) / Length(A) / Length(B));
    41 }
    42 
    43 Vector Rotate(Vector A, double rad){
    44     return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));
    45 }
    46 
    47 double Cross(Vector A, Vector B){
    48     return A.x * B.y - A.y * B.x;
    49 }
    50 
    51 Point GetLineIntersection(Point P, Vector v, Point Q, Vector w){
    52     Vector u = P - Q;
    53     double t = Cross(w, u) / Cross(v, w);
    54     return P + v * t;
    55 }
    56 
    57 Point GetD(Point A, Point B, Point C){
    58     Vector v1 = C - B;
    59     double a1 = Angle((A - B), v1);
    60     v1 = Rotate(v1, a1 / 3);
    61 
    62     Vector v2 = B - C;
    63     double a2 = Angle((A - C), v2);
    64     v2 = Rotate(v2, -a2 / 3);
    65 
    66     return GetLineIntersection(B, v1, C, v2);
    67 }
    68 
    69 
    70 int main(){
    71     scanf("%d", &t);
    72     while(t--){
    73         scanf("%lf%lf%lf%lf%lf%lf", &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("%.6f %.6f %.6f %.6f %.6f %.6f
    ", D.x, D.y, E.x, E.y, F.x, F.y);
    78     }
    79 }
  • 相关阅读:
    linux -- 基于zookeeper搭建yarn的HA高可用集群
    Linux -- 之HDFS实现自动切换HA(全新HDFS)
    Hadoop格式化 From hu-hadoop1/192.168.11.11 to hu-hadoop2:8485 failed on connection exception: java.net.
    Directory /home/hdfs/name is in an inconsistent state: storage directory does not exist or is not a
    react学习01
    单页面应用(spa)引入百度地图(Cannot read property 'dc' of undefined)
    npm 发布包
    Vue学习-01
    echarts3.0使用总结
    webpack学习--创建一个webpack打包流程
  • 原文地址:https://www.cnblogs.com/Dillonh/p/8780545.html
Copyright © 2020-2023  润新知