UVa 11178 Morley‘s Theorem(计算几何基础)

 

题目链接:https://www.luogu.com.cn/problem/UVA11178 

 有 T 组测试样例,输入 3 个点的坐标,A , B , C ,然后每两点确定一条直线,将每两条直线所形成的夹角三等分,每两条角平分线确定一个点,输出确定的这三个点

如图所示,我们可以确定向量 BD,CD,这样这两个向量之间的交点就可以算出来,BD 是由 BC 逆时针旋转 α/3 得到的,CD 是由 CB 顺时针旋转 α/3 得到的,所以这样求出 α 的角度,问题就可以解决了

double sgn(double x)
{
    if(fabs(x)<eps) return 0;
    if(x<0) return -1;
    if(x>0) return 1;
}
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 b){ return Vector(a.x*b,a.y*b); }
Vector operator/(Vector a,double b){ return Vector(a.x/b,a.y/b); }
bool operator<(const Point a,const Point b){ return a.x<b.x || a.x==b.x&&a.y<b.y; }
bool operator==(const Point a,const Point b){ return sgn(a.x-b.x)==0 && sgn(a.y-b.y)==0; }

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)
{
    return Vector(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}

Point get_interpoint(Point a,Vector v,Point b,Vector w)
{
    Vector u=a-b;
    double t=Cross(w,u)/Cross(v,w);
    return a+v*t;
}

Point go(Point a,Point b,Point c)
{
    double rad=angle(a-b,c-b);
    Vector x=rotate(c-b,rad/3); //逆时针旋转
    
    rad=angle(b-c,a-c);
    Vector y=rotate(b-c,-rad/3); //顺时针旋转

    return get_interpoint(b,x,c,y);
}

int main()
{
    //IOS;
    rush(){
        Point a,b,c;
        sff(a.x,a.y);
        sff(b.x,b.y);
        sff(c.x,c.y);
        Point ans=go(a,b,c); //∠ABC
        printf("%.6lf %.6lf ",ans.x,ans.y);
        ans=go(b,c,a);
        printf("%.6lf %.6lf ",ans.x,ans.y);
        ans=go(c,a,b);
        printf("%.6lf %.6lf\n",ans.x,ans.y);
    }
    PAUSE;
    return 0;
}

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 酷酷鲨 设计师:CSDN官方博客 返回首页