CodeForces 630 O. Arrow(计算几何)

Description
箭矢形状如下图,给出箭头中心坐标(px,py)、箭头的方向向量(vx,vy)及几个长度(如图标注),求箭矢七个顶点坐标
CodeForces 630 O. Arrow(计算几何)_第1张图片
Input
八个整数px,py,vx,vy,a,b,c,
(-1000<=px,py,vx,vy<=1000,vx*vx+vy*vy>0,1<=a,b,c,d<=1000,a>c)
Output
从箭头开始逆时针输出七个顶点坐标,每个顶点坐标占一行,要求结果与精确值相对误差不超过1e-9
Sample Input
8 8 0 2 8 3 4 5
Sample Output
8.000000000000 11.000000000000
4.000000000000 8.000000000000
6.000000000000 8.000000000000
6.000000000000 3.000000000000
10.000000000000 3.000000000000
10.000000000000 8.000000000000
12.000000000000 8.000000000000
Solution
简单计算几何
Code

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
double px,py,vx,vy,a,b,c,d,x[8],y[8];
int main()
{
    while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&px,&py,&vx,&vy,&a,&b,&c,&d))
    {
        double tx=vx/sqrt(vx*vx+vy*vy),ty=vy/sqrt(vx*vx+vy*vy);
        x[1]=b*tx+px,y[1]=b*ty+py;
        x[7]=a*ty/2+px,y[7]=-a*tx/2+py;
        x[2]=-a*ty/2+px,y[2]=a*tx/2+py;
        x[6]=c*ty/2+px,y[6]=-c*tx/2+py;
        x[3]=-c*ty/2+px,y[3]=c*tx/2+py;
        x[4]=x[3]-d*tx,y[4]=y[3]-d*ty;
        x[5]=x[6]-d*tx,y[5]=y[6]-d*ty;
        for(int i=1;i<=7;i++)printf("%.10lf %.10lf\n",x[i],y[i]);
    }
    return 0;
}

你可能感兴趣的:(CodeForces 630 O. Arrow(计算几何))