您的位置:首页 > 其它

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

2014-10-13 16:42 267 查看
题意:

Morley定理:任意三角形中,每个角的三等分线,相交出来的三个点构成一个正三角形。

不过这和题目关系不大,题目所求是正三角形的三个点的坐标,保留6位小数。

分析:

由于对称性,求出D点,EF也是同样的。

用点和向量的形式表示一条直线,向量BA、BC的夹角为a1,则将BC逆时针旋转a1/3可求得 直线BD,同理也可求得直线CD,最后再求交点即可。

//#define LOCAL
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

struct Point
{
double x, y;
Point(double x=0, double y=0) :x(x),y(y) {}
};
typedef Point Vector;
const double EPS = 1e-10;

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); }

Vector operator / (Vector A, double p)    { return Vector(A.x/p, A.y/p); }

bool operator < (const Point& a, const Point& b)
{ return a.x < b.x || (a.x == b.x && a.y < b.y); }

int dcmp(double x)
{ if(fabs(x) < EPS) return 0; else x < 0 ? -1 : 1; }

bool operator == (const Point& a, const Point& b)
{ return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0; }

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; }

double Area2(Point A, Point B, Point C)
{ return Cross(B-A, C-A); }

Vector VRotate(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 read_point(void)
{
double x, y;
scanf("%lf%lf", &x, &y);
return Point(x, y);
}

Point GetD(Point A, Point B, Point C)
{
Vector v1 = C - B;
double a1 = Angle(A-B, v1);
v1 = VRotate(v1, a1/3);

Vector v2 = B - C;
double a2 = Angle(A-C, v2);
v2 = VRotate(v2, -a2/3);

return GetLineIntersection(B, v1, C, v2);
}

int main(void)
{
#ifdef    LOCAL
freopen("11178in.txt", "r", stdin);
#endif

int T;
scanf("%d", &T);
while(T--)
{
Point A, B, C, D, E, F;
A = read_point();
B = read_point();
C = read_point();
D = GetD(A, B, C);
E = GetD(B, C, A);
F = GetD(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;
}


代码君
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: