Hdu 3365 New Ground(计算几何)

58 篇文章 0 订阅
11 篇文章 0 订阅

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3365

思路: 以A[0]为原点,构造向量A[i]-A[0]。先旋转(注意旋转方向),再伸缩,最后平移至终点。

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#define debu
using namespace std;
const double eps=1e-7;
const int maxn=1e4+50;
const double pi=acos(-1.0);
struct Vector
{
    double x,y;
    Vector(double x=0,double y=0):x(x),y(y) {}
};
int n;
Vector A[maxn],B[5];
Vector operator + (const Vector &A,const Vector &B)
{
    return Vector(A.x+B.x,A.y+B.y);
}
Vector operator - (const Vector &A,const Vector &B)
{
    return Vector(A.x-B.x,A.y-B.y);
}
Vector operator * (const Vector &A,const double &p)
{
    return Vector(A.x*p,A.y*p);
}
int dcmp(double x)
{
    if(fabs(x)<eps) return 0;
    else return x<0?-1:1;
}
double Dot(const Vector &A,const Vector &B)
{
    return A.x*B.x+A.y*B.y;
}
double Length(const Vector &A)
{
    return sqrt(Dot(A,A));
}
double Cross(const Vector &A,const Vector &B)
{
    return A.x*B.y-A.y*B.x;
}
Vector Rotate(const Vector &A,double rad)
{
    return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
int main()
{
#ifdef debug
    freopen("in.in","r",stdin);
#endif // debug
    int t,cas=0;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=0; i<n; i++)
            scanf("%lf%lf",&A[i].x,&A[i].y);
        for(int i=0; i<2; i++)
            scanf("%lf%lf",&B[i].x,&B[i].y);
        Vector tmp1,tmp2;
        tmp1=A[1]-A[0];
        tmp2=B[1]-B[0];
        double len=Length(tmp2)/Length(tmp1);
        double rad=acos(Dot(tmp1,tmp2)/(Length(tmp1)*Length(tmp2)));
        //cout<<rad<<endl;
        if(Cross(tmp1,tmp2)<eps) rad=2.0*pi-rad;
        //cout<<"rad "<<rad<<endl;
        for(int i=2; i<n; i++)
        {
            A[i]=A[i]-A[0];
            //cout<<"flag "<<A[i].x<<" "<<A[i].y<<endl;
            A[i]=Rotate(A[i],rad);
            //cout<<A[i].x<<" "<<A[i].y<<endl;
            A[i]=A[i]*len;
            A[i]=A[i]+B[0];
        }
        printf("Case %d:\n",++cas);
        printf("%.2f %.2f\n",B[0].x,B[0].y);
        printf("%.2f %.2f\n",B[1].x,B[1].y);
        for(int i=2; i<n; i++)
            printf("%.2f %.2f\n",A[i].x,A[i].y);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值