Morley's Theorem UVA - 11178

向量函数板
题意:给你一个三角形的三个点abc,求他们的三等分点的交点

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
const int N = 13;
const int M= 1<<N;
int st[M],ma[M];
int dp[N][M];


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 b)
{
    return Vector(a.x*b,a.y*b);
}
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 cross(Vector a,Vector b)//叉乘
{
    return a.x*b.y-a.y*b.x;
}

double len (Vector a)
{
    return sqrt(a.x*a.x+a.y*a.y);
}

Vector rotate1(Vector a,double rad)//逆时针旋转rad
{
    return Vector(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}

point getans (point p,Vector v,point q,Vector w)//求两条直线的交点,唯一交点,当且仅当不共线
{
    Vector u=p-q;
    double t=cross(w,u)/cross(v,w);
    return p+v*t;
}

point getPoint(point a,point b,point c)
{
    Vector bc=c-b;
    Vector ba=a-b;
    double rad=acos(dot(bc,ba)/len(bc)/len(ba));
    Vector bd=rotate1(bc,rad/3);

    Vector cb=b-c;
    Vector ca=a-c;
    double rad1=acos(dot(cb,ca)/len(cb)/len(ca));
    Vector cd=rotate1(cb,-rad1/3);

    return getans(b,bd,c,cd);

}


int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        point a,b,c;
        scanf("%lf %lf %lf %lf %lf %lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y);
        point d=getPoint(a,b,c);//后两个的 顺序不能写反了,因为有顺时针逆时针的方向问题
        point e=getPoint(b,c,a);
        point f=getPoint(c,a,b);
        printf("%.6f %.6f ",d.x,d.y);
        printf("%.6f %.6f ",e.x,e.y);
        printf("%.6f %.6f\n",f.x,f.y);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值