您的位置:首页 > 其它

uva 11178 morley定理(计算几何基础)

2014-09-08 16:40 447 查看
莫雷定理是说:对于任意一个三角形,从每个角引出两条三等分线,共六条线,可以分成三对,得到三个点。这三个点恰好是一个等边三角形的顶点。。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <limits>
#include <set>
#include <map>

using namespace std;

#define MIN(a, b) a < b ? a : b
#define MAX(a, b) a > b ? a : b
#define F(i, n) for (int i=0;i<(n);++i)
#define REP(i, s, t) for(int i=s;i<=t;++i)
#define IREP(i, s, t) for(int i=s;i>=t;--i)
#define REPOK(i, s, t, o) for(int i=s;i<=t && o;++i)
#define MEM0(addr, size) memset(addr, 0, size)
#define LBIT(x) x&-x

#define PI 3.1415926535897932384626433832795
#define HALF_PI 1.5707963267948966192313216916398

#define MAXN 100 + 10
#define MAXM 100
#define MOD 20071027

typedef long long LL;

const double maxdouble = numeric_limits<double>::max();
const double eps = 1e-16;
const int INF = 0x7FFFFFFF;

struct Point {
double x, y;
Point(){};
Point(double x, double y):x(x),y(y){};
};
typedef Point Vector;

Vector operator - (Point A, Point B) {
return Vector(A.x-B.x, A.y - B.y);
}
Vector operator + (Point A, Point 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);
}
int dcmp(double x) {
if (fabs(x) < eps)
return 0;
else
return x < 0 ? -1 : 1;
}

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

double Dot(Vector A, Vector B) {
return A.x*B.x + A.y*B.y;
}
double Cross(Vector A, Vector B) {
return A.x*B.y-A.y*B.x;
}
double Length(Vector A) {
return sqrt(Dot(A, A));
}
double Area2(Point A, Point B, Point C) {
return Cross(B-A, C-A);
}
double Angle(Vector A, Vector B) {
return acos(Dot(A, B) / Length(A) / Length(B));
}
Vector Rotate(Vector A, double rad) {
return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
}
// 单位法线 左转90度后归一化
Vector Normal(Vector A) {
double L = Length(A);
return Vector(-A.y/L, A.x/L);
}
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;
}
double cos_theorem(double edge1, double edge2, double edge3) {
return acos((pow(edge1, 2.0) + pow(edge2, 2.0) - pow(edge3, 2.0)) / (2*edge1*edge2));
}
int main()
{
freopen("input.in", "r", stdin);
int N;
Point pt[3];
Vector v[3];
cin >> N;
F(cases, N) {
F(i, 3)
cin >> pt[i].x >> pt[i].y;

v[0] = pt[1] - pt[0];
v[1] = pt[2] - pt[1];
v[2] = pt[0] - pt[2];

double a0 = cos_theorem(Length(v[0]), Length(v[2]), Length(v[1])),
a1 = cos_theorem(Length(v[0]), Length(v[1]), Length(v[2])),
a2 = cos_theorem(Length(v[2]), Length(v[1]), Length(v[0]));

Point pt1 = GetLineIntersection(pt[0], Rotate(v[0], a0/3), pt[1], Rotate(v[1], a1/3*2)),
pt2 = GetLineIntersection(pt[1], Rotate(v[1], a1/3), pt[2], Rotate(v[2], a2/3*2)),
pt3 = GetLineIntersection(pt[2], Rotate(v[2], a2/3), pt[0], Rotate(v[0], a0/3*2));

printf("%.6f %.6f %.6f %.6f %.6f %.6f\n", pt2.x, pt2.y, pt3.x, pt3.y, pt1.x, pt1.y);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: