码迷,mamicode.com
首页 > 其他好文 > 详细

UVa 11178 Morley's Theorem (几何问题)

时间:2016-05-31 20:54:39      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

题意:给定三角形的三个点,让你求它每个角的三等分线所交的顶点。

析:根据自己的以前的数学知识,应该很容易想到思想,比如D点,就是应该求直线BD和CD的交点,

以前还得自己算,现在计算机帮你算,更方便,主要注意的是旋转是顺时针还是逆时针,不要搞错了。

要求BD和CD就得先求那个夹角ABC和ACD,然后三等分。

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
const int maxn = 500 + 10;
const double eps = 1E-10;
struct Point{
    double x, y;
    Point(double xx = 0, double yy = 0) : x(xx), y(yy) {  }
};
typedef Point Vector;

Vector operator + (Vector A, Vector B) { return Vector(A.x+B.x, A.y+B.y);  }
Vector operator - (Vector A, Vector 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);  }
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 - A.y*B.x;  }
Vector Rotate(Vector A, double 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;
    double t = Cross(w, u) / Cross(v, w);
    return P + v*t;
}

Point solve(Point A, Point B, Point C){
    double abc = Angle(A-B, C-B) / 3.0;
    Vector BD = Rotate(C-B, abc);
    double acb = Angle(A-C, B-C) / 3.0;
    Vector CD = Rotate(B-C, -acb);

    return GetLineIntersection(B, BD, C, CD);
}

int main(){
    int T;  cin >> T;
    Point A, B, C, D, E, F;
    double x, y;
    while(T--){
        scanf("%lf %lf", &x, &y);   A = Point(x, y);
        scanf("%lf %lf", &x, &y);   B = Point(x, y);
        scanf("%lf %lf", &x, &y);   C = Point(x, y);

        D = solve(A, B, C);
        E = solve(B, C, A);
        F = solve(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;
}

 

UVa 11178 Morley's Theorem (几何问题)

标签:

原文地址:http://www.cnblogs.com/dwtfukgv/p/5547292.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!