题目地址:
http://acm.hust.edu.cn/vjudge/problem/18543
函数较多,作为模板。
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
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);}
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;
}
Vector Rotate(Vector A , double rad)//向量旋转(逆时针是正角)
{
return Vector(A.x*cos(rad) - A.y*sin(rad) , A.x*sin(rad) + A.y*cos(rad));
}
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));}//向量之间夹角
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--)
{
scanf("%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y);
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;
}