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 }

代码君

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

时间: 2024-08-05 19:35:34

UVa 11178 (简单练习) Morley's Theorem的相关文章

简单几何 UVA 11178 Morley&#39;s Theorem

题目传送门 题意:莫雷定理,求三个点的坐标 分析:训练指南P259,用到了求角度,向量旋转,求射线交点 /************************************************ * Author :Running_Time * Created Time :2015/10/21 星期三 15:56:27 * File Name :UVA_11178.cpp ************************************************/ #include

UVA 11178 Morley&#39;s Theorem 计算几何

计算几何: 最基本的计算几何,差积  旋转 Morley's Theorem Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the line

UVa 11178 Morley&#39;s Theorem (几何问题)

题意:给定三角形的三个点,让你求它每个角的三等分线所交的顶点. 析:根据自己的以前的数学知识,应该很容易想到思想,比如D点,就是应该求直线BD和CD的交点, 以前还得自己算,现在计算机帮你算,更方便,主要注意的是旋转是顺时针还是逆时针,不要搞错了. 要求BD和CD就得先求那个夹角ABC和ACD,然后三等分. 代码如下: #include <iostream> #include <cstdio> #include <cstring> #include <cmath&

UVA 11178 Morley&#39;s Theorem(旋转+直线交点)

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18543 [思路] 旋转+直线交点 第一个计算几何题,照着书上代码打的. [代码] 1 #include<cstdio> 2 #include<cmath> 3 #include<cstring> 4 using namespace std; 5 6 7 struct Pt { 8 double x,y; 9 Pt(double x=0,d

UVA - 11178 - Morley&#39;s Theorem (计算几何~~)

UVA - 11178 Morley's Theorem Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the lines trisecti

uva 11178 Morley&amp;#39;s Theorem(计算几何-点和直线)

Problem D 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

uva 11178 Morley&#39;s Theorem(计算几何-点和直线)

Problem D 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

A - Morley&#39;s Theorem UVA - 11178

#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<string> using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); int sgn(double x){ if(fabs(x) < e

UVA 11178 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-s