就是求一个三角形的6条角三分线构成的一个正三角形的坐标。
算出角度,直接直线相交求交点。
简单题,主要是为了验证我的模板的正确性。
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const double eps = 1e-10;
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 - (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 B)
{
return Vector(A.x / B,A.y / B);
}
bool operator < (Vector A, Vector B)
{
return A.x < B.x || (A.x == B.x && A.y < B.y);
}
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 fabs(A.x * B.y - A.y * B.x);
}
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 GLIs(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 A,Point B,Point C)
{
Vector a1 = A - B , a2 = C - B;
double rad1 = Angle(a1,a2); rad1 /= 3;
Vector a3 = A - C , a4 = B - C;
double rad2 = Angle(a3,a4); rad2 = rad2 * -1 / 3;
Vector a = Rotate(a2,rad1);
Vector b = Rotate(a4,rad2);
return GLIs(B,a,C,b);
}
Point Read_Point()
{
Point a;
scanf("%lf%lf",&a.x,&a.y);
return a;
}
int main()
{
int T;
scanf("%d",&T);
for (int cas = 1;cas <= T;cas++)
{
Point A,B,C,D,E,F;
A = Read_Point();
B = Read_Point();
C = Read_Point();
D = solve(A,B,C);
E = solve(B,C,A);
F = solve(C,A,B);
//printf("%f %f %f %f %f %f\n",A.x,A.y,B.x,B.y,C.x,C.y);
printf("%.6f %.6f %.6f %.6f %.6f %.6f\n",D.x,D.y,E.x,E.y,F.x,F.y);
}
return 0;
}