您的位置:首页 > 其它

UVA11178 Morley's Theorem(基础模板)

2016-04-20 17:02 169 查看
题目链接

题意:给出A,B, C点坐标求D,E,F坐标,其中每个角都被均等分成三份

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
struct Point
{
double x, y;
};
typedef Point Vector;
Vector operator + (Vector A, Vector B)
{
Vector C;
C.x = A.x + B.x;
C.y = A.y + B.y;
return C;
}
Vector operator - (Vector A, Vector B)
{
Vector C;
C.x = A.x - B.x;
C.y = A.y - B.y;
return C;
}
Vector operator *(Vector A, double b)
{
Vector C;
C.x = A.x * b;
C.y = A.y * b;
return C;
}
Point read_point()
{
Point temp;
scanf("%lf%lf", &temp.x, &temp.y);
return temp;
}
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));
}
Vector Rotate(Vector A, double rad)
{
Vector C;
C.x = A.x * cos(rad) - A.y * sin(rad);
C.y = A.x * sin(rad) + A.y * cos(rad);
return C;
}
double Cross(Vector A, Vector B)
{
return A.x * B.y - A.y * B.x;
}
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 getD(Point A, Point B, Point C)
{
Vector v1 = C - B;
double a1 = Angle(A - B, v1);
v1 = Rotate(v1, a1 / 3);

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

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

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


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