hdu 4998

给n次操作,每次操作为x, y, p即绕点(x,y)旋转p度,经过n次旋转后,相当于绕某个固定点旋转多少度,求固定点坐标和旋转度数。


假设对图片上任意点(x,y),绕一个坐标点(rx0,ry0)逆时针旋转a角度后的新的坐标设为(x0, y0),有公式:
    x0= (x - rx0)*cos(a) - (y - ry0)*sin(a) + rx0 ;


    y0= (x - rx0)*sin(a) + (y - ry0)*cos(a) + ry0 ;
求出末点,再公式倒推求新的绕点(rx0,ry0

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define N 100050
typedef long long ll;
const int MOD = 1e9+7;

#define PI acos(-1)
int  main()
{
    double stx, sty, endx, endy, x, y, p, endp, xx, yy;
    int t, n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        stx=sty=xx=yy=endp=0;
        while(n--)
        {
            scanf("%lf %lf %lf",&x,&y,&p);
            endp+=p;
            if(endp>=2*PI) endp-=2*PI;
            endx=(xx-x)*cos(p)-(yy-y)*sin(p)+x;
            endy=(xx-x)*sin(p)+(yy-y)*cos(p)+y;
            xx=endx;
            yy=endy;
        }
        x=((endx-stx*cos(endp)+sty*sin(endp))*(1-cos(endp))-(endy-stx*sin(endp)-sty*cos(endp))*sin(endp))/(2-2*cos(endp));
        y=((endx-stx*cos(endp)+sty*sin(endp))*(1-cos(endp))-(1-cos(endp))*(1-cos(endp))*x)/((1-cos(endp))*sin(endp));
        printf("%.10lf %.10lf %.10lf\n",x,y,endp);
    }
    return 0;
}

  

转载于:https://www.cnblogs.com/Przz/p/5409768.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值