#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;
Vector operator - (Point A,Point B)//重载运算符
{
return Vector(A.x-B.x,A.y-B.y);
}
Vector operator *(Point A,double p)
{
return Vector(A.x*p,A.y*p);
}
Vector operator + (Point A,Point B)
{
return Vector(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 Cross(Vector A,Vector B)//叉积
{
return A.x*B.y-B.x*A.y;
}
double Angle(Vector A,Vector B)//向量的夹角
{
return acos(Dot(A,B) / Length(A) / Length(B));
}
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)//A向量旋转rad,逆时针
{
return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
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);
}
Point read_point()
{
int x,y;
scanf("%d %d",&x,&y);
return Vector(x,y);
}
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;
}
计算几何的基本模板
本文提供了一个计算几何的基础模板,包括向量操作、点积、叉积等关键算法,并实现了求解三角形内特定交点的功能。
6万+

被折叠的 条评论
为什么被折叠?



