uva 11178 计算几何

题目地址:
http://acm.hust.edu.cn/vjudge/problem/18543

函数较多,作为模板。

#include <iostream>
#include <cstdio>
#include <cmath>
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 - (point A,point 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);}

double Cross(Vector A , Vector B)//向量叉积
{
    return A.x * B.y - A.y * B.x;
}

point GetLineIntersection(point P ,Vector v , point Q , Vector w) //两直线交点(参数法)
{
    Vector u = P-Q;
    double t = Cross(w , u) / Cross(v ,w);
    return P+v*t;
}

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(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));}//向量之间夹角

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

int main()
{
    int T;
    point A,B,C,D,E,F;
    scanf("%d",&T);
    while(T--)
    {
      scanf("%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y);
      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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值