UVa 11178 Morley's Theorem (几何问题)
Posted dwtfukgv
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVa 11178 Morley's Theorem (几何问题)相关的知识,希望对你有一定的参考价值。
题意:给定三角形的三个点,让你求它每个角的三等分线所交的顶点。
析:根据自己的以前的数学知识,应该很容易想到思想,比如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 (几何问题)的主要内容,如果未能解决你的问题,请参考以下文章
[日常摸鱼]Uva11178Morley's Theorem-几何
UVA_11178_Morley's_Theorem_(向量旋转+直线相交)