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

  

posted @ 2015-09-07 13:01  Przz  阅读(135)  评论(0编辑  收藏  举报