欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

UVA-11178-计算几何

程序员文章站 2022-04-02 19:24:37
...

题目大意:求一个三角形中每个内角的角三等分线组成的三角形的三个点的坐标;

题目解析:没有算法可言,直接上模板;

AC代码:

#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 + (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 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);
}
const double eps=1e-10;
int dcmp(double x)
{
    if(fabs(x)<eps) return 0;
    else return x<0?-1:1;
}
bool operator == (const Point& a,const Point& b)
{
    return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0;
}
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 A.x*B.y-A.y*B.x;}                    //点的叉积
double Area2(Point A,Point B,Point C){return Cross(B-A,C-A);}                    //三点构成的三角形面积的两倍
Vector Rotate(Vector A,double rad)    {return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));}     //向量逆时针旋转
Vector Normal(Vector A)                                                            //向量的法线
{
    double L = Length(A);
    return Vector(-A.y/L,A.x/L);
}

//定义直线P+tv,计算两直线的交点,前提是两直线不平行
Point GetLineIntersection(Point P,Point v,Point Q,Point w)
{
    Vector u=P-Q;
    double t=Cross(w,u)/Cross(v,w);
    return P+v*t;
}
 //点到直线的距离
double DistanceToLine(Point P,Point A,Point B)
{
    Vector v1=B-A,v2=P-A;
    return fabs(Cross(v1,v2))/Length(v1);
}
 //点到线段的距离
double DistanceToSegement(Point P,Point A,Point B)
{
    if(A==B)    return Length(P-A);
    Vector v1=B-A,v2=P-A,v3=P-B;
    if(dcmp(Dot(v1,v2))<0)  return Length(v2);
    else if(dcmp(Dot(v1,v3))>0) return Length(v3);
    else return fabs(Cross(v1,v2))/Length(v1);
}
 //点在直线上的投影
Point GetLineProjection(Point P,Point A,Point B)
{
    Vector v=B-A;
    return A+v*(Dot(v,P-A)/Dot(v,v));
}
 //判断两直线是否规范相交
bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2)
{
    double c1=Cross(a2-a1,b1-a1),c2=Cross(a2-a1,b2-a1),c3=Cross(b2-b1,a1-b1),c4=Cross(b2-b1,a2-b1);
    return dcmp(c1)*dcmp(c2)<0&&dcmp(c3)*dcmp(c4)<0;
}
 //计算多边形的有向面积
 double PolygonArea(Point* p,int n)
 {
     double area=0;
     for(int i=1;i<n-1;i++)
     {
         area+=Cross(p[i]-p[0],p[i+1]-p[0]);
     }
     return area/2;
 }

Point fun(Point a,Point b,Point c)
{
    double ang=Angle(b-a,c-a);
    Point v1=Rotate(b-a,ang/3);
    ang=Angle(a-b,c-b);
    Point v2=Rotate(a-b,-ang/3);
    return GetLineIntersection(a,v1,b,v2);
}
int main()
{
    Point a,b,c,d,e,f;
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lf",&a.x,&a.y);
        scanf("%lf%lf",&b.x,&b.y);
        scanf("%lf%lf",&c.x,&c.y);
        d=fun(b,c,a);
        e=fun(c,a,b);
        f=fun(a,b,c);
        printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n",d.x,d.y,e.x,e.y,f.x,f.y);
    }
    return 0;
}