您的位置:首页 > 其它

UVA 11178 Morley's Theorem——直线相交

2017-09-24 11:14 381 查看
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const double eps = 1e-5;
const double PI = acos(-1.0);
struct Point {
double x, y;
Point (double xx = 0.0, double yy = 0.0) : x(xx), y(yy) {}
};
typedef Point Vector;

Point operator + (const Point &p1, const Point &p2) { return Point(p1.x + p2.x, p1.y + p2.y); }
Point operator - (const Point &p1, const Point &p2) { return Point(p1.x - p2.x, p1.y - p2.y); }
Vector operator * (const Vector &v, double x) { return Vector(v.x*x, v.y*x); }

double Dot(Vector v1, Vector v2) { return v1.x*v2.x+v1.y*v2.y; }

double Length(Vector v) { return sqrt(Dot(v, v)); }

double Angle(Vector v1, Vector v2) { return acos(Dot(v1, v2) / Length(v1) / Length(v2)); }

double Cross(Vector v1, Vector v2) { return v1.x*v2.y - v1.y*v2.x; }

Vector Rotate(Vector v, double rad) { return Vector(v.x*cos(rad) - v.y*sin(rad), v.x*sin(rad) + v.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 p1, Point p2, Point p3) {
Vector v1 = p2 - p1, v2 = p3 - p1, v3 = p3 - p2;
double angle1 = Angle(v1, v2), angle2 = PI - Angle(v1, v3);
angle1 /= 3.0, angle2 /= 3.0;
Vector t1 = Rotate(v1, angle1), t2 = Rotate(v1, PI - angle2);
return GetLineIntersection(p1, t1, p2, t2);
}

int main() {
int T; scanf("%d", &T);
Point A, B, C, D, E, F;
for (int kase = 1; kase <= T; kase++) {
scanf("%lf %lf %lf %lf %lf %lf", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y);
D = Solve(B, C, A);
E = Solve(C, A, B);
F = Solve(A, B, C);
printf("%lf %lf %lf %lf %lf %lf\n", D.x, D.y, E.x, E.y, F.x, F.y);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: