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

Uva11178计算几何

程序员文章站 2022-04-02 19:01:21
...

题目链接:点击打开链接

题意:做三角形ABC内角的三等分线,交与DEF点求这三点的坐标

D点是向量BC向逆时针旋转B/3弧度和向量CB顺时针旋转C/3的交点,其他也是也一样,用向量旋转和直线相交的模板就可以做出来了

#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;

const double eps = 1e-8;



struct Point//点 向量
{
    double x,y;
    Point(double x=0,double y=0):x(x),y(y) {}
};
typedef  Point  Vector;
//向量使用点作为表示方法 结构相同 为了代码清晰定义宏加以区别
int dcmp(double x) //三态函数 处理与double零有关的精度问题
{
    if(fabs(x) < eps)    return 0;
    return x<0 ? -1 : 1;
}
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 Vector& A, const Vector& B)
{
    return dcmp(A.x-B.x)==0 && dcmp(A.y-B.y)==0;
}
bool operator < (const Point&a,const Point &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 Cross(Vector A, Vector B)  //向量叉积
{
    return A.x * B.y - A.y * B.x;
}
double Length(Vector A) //向量长度
{
    return sqrt(Dot(A,A));
}
double Angle(Vector A, Vector B)  //向量夹角
{
    return acos(Dot(A,B) / Length(A) / Length(B));
}
Vector Rotate(Vector A, double rad) //向量旋转 rad为弧度
{
    return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));
}
//直线向量参数方程 P+tv P为点,v为单位向量 (v长度无用)
Point GetLineIntersection(Point P, Vector v, Point Q, Vector w)//获取直线交点
{
    //调用应保证P,Q有交点 : 即 Cross(v,w)!=0
    Vector u = P-Q;
    double t = Cross(w,u) / Cross(v,w);
    return P+v*t;
}

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()
{
    double x,y;
    scanf("%lf %lf",&x,&y);
    return Point(x,y);
}
 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;
}