直线的旋转与相交,计算几何(Morley定理,uva 11178)

本文介绍了一个计算几何的基础算法实现,包括向量运算、求交点、旋转向量等核心功能,并通过具体函数实现了三角形内特定点的计算。代码采用C++编写,展示了如何进行点与向量操作。

计算几何基础题

以后还是少瞄答案,看分析做没用的,把分析以下的部分遮住即可。


代码

#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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值