zoukankan      html  css  js  c++  java
  • 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
    ",x,y,endp);
        }
        return 0;
    }
    

      

  • 相关阅读:
    Tcp/ip 报文解析
    使用redis构建可靠分布式锁
    提高服务器程序性能的一些方法
    socket读写返回值的处理
    也写年终总结
    记录服务上线一年来的点点滴滴
    C++实现线程安全的单例模式
    一步一步实现读写锁
    从I/O复用谈epoll为什么高效
    同域SQL server 做镜像服务器遇到1418错误
  • 原文地址:https://www.cnblogs.com/Przz/p/5409768.html
Copyright © 2011-2022 走看看