转载请注明出处:忆梦http://blog.csdn.net/yimeng2013/article/details/17327339
白书例题:259面
计算几何第一题
//UVA Morley定理
#include<cstdio>
#include<cmath>
struct Point
{
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
};
typedef Point Vector;
//向量+向量=向量 点+向量=点
Vector operator + (Vector A, Vector 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);}
//向量/数=向量
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);
}
//点积:两者长度乘积在乘上夹角余弦 XaXb + YaYb
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));
}
//叉积:两向量v和w的叉积等于v和w组成的三角形的有向面积的两倍 XaYb - XbYa
double Cross(Vector A, Vector B)
{
return A.x*B.y - A.y*B.x;
}
//向量旋转 x' = xcosa - ysina, y' = xsina + ycosa(a为逆时针旋转的角)
//rad是弧度
Vector Rotate(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()
{
Point temp;
scanf("%lf %lf", &temp.x, &temp.y);
return temp;
}
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;
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 ;
}