计算几何基础题
以后还是少瞄答案,看分析做没用的,把分析以下的部分遮住即可。
代码
#include<bits/stdc++.h>
using namespace std;
struct Point
{
double x,y;
Point(double x=0,double y=0):x(x),y(y){}
};
typedef Point Vector;
Point read()
{
double x,y;
scanf("%lf %lf",&x,&y);
return Point(x,y);
}
Vector operator - (Point A,Point B)
{
return Vector(A.x-B.x,A.y-B.y);
}
Vector operator * (double t,Vector A)
{
return Vector(A.x*t,A.y*t);
}
Point operator + (Point A,Vector B)
{
return Point(A.x+B.x,A.y+B.y);
}
double Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
}
Point GetInterSection(Point P,Vector v,Point Q,Vector w)
{
Vector u=P-Q;
double t1=Cross(w,u)/Cross(v,w);
return P+t1*v;
}
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(Point A,Point B)
{
return A.x*B.x+A.y*B.y;
}
double Len(Vector A)
{
return sqrt(Dot(A,A));
}
double GetAngle(Vector A,Vector B)
{
return acos(Dot(A,B)/Len(A)/Len(B));
}
Point GetD(Point A,Point B,Point C)
{
double rad=GetAngle(A-B,C-B);
rad/=3;
Vector v1=C-B;
v1=Rotate(v1,rad);
rad=GetAngle(A-C,B-C);
rad/=3;
Vector v2=B-C;
v2=Rotate(v2,-rad);
return GetInterSection(B,v1,C,v2);
}
int main()
{
int N;
Point A,B,C,D,E,F;
scanf("%d",&N);
while(N--)
{
A=read();
B=read();
C=read();
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;
}