http://acm.hdu.edu.cn/showproblem.php?pid=4998
http://blog.csdn.net/wcyoot/article/details/33310329
一个旋转变换可以转化为一个三维矩阵的变化
绕(x,y)旋转角度r,执行十次,求等价旋转点和角度
绕原点矩阵如下
由于是绕(x,y),x1 = (x-x0)*cos0 - (y-y0)*sin0 + x0;y1同理,那么第三行前两列即为x0*(1-cos(r)) + y0*sin(r)和y0*(1-cos(r)) - x0*sin(r)
最后根据x0*(1-cos(r)) + y0*sin(r) = v[2][0]和y0*(1-cos(r)) - x0*sin(r) = v[2][1]列出方程即可求解等价的x0,y0
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <queue> #include <map> #include <iostream> #include <algorithm> using namespace std; #define RD(x) scanf("%d",&x) #define RD2(x,y) scanf("%d%d",&x,&y) #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z) #define clr0(x) memset(x,0,sizeof(x)) typedef long long LL; double x,y,r; const double pi = acos(-1.0); struct Matrix { double v[3][3]; Matrix(){ for(int i = 0;i < 3;++i) for(int j = 0;j < 3;++j) v[i][j] = 0; } void id(){ for(int i = 0;i < 3;++i) v[i][i] = 1; } void init(){ v[1][1] = v[0][0] = cos(r); v[1][0] = -(v[0][1] = sin(r)); v[2][0] = x*(1-cos(r)) + y*sin(r); v[2][1] = y*(1-cos(r)) - x*sin(r); v[2][2] = 1; } Matrix operator * (Matrix c){ Matrix ans; for(int i = 0;i < 3;++i) for(int j = 0;j < 3;++j) for(int k = 0;k < 3;++k) ans.v[i][j] += v[i][k]*c.v[k][j]; return ans; } }; int main() { int _,n;RD(_);while(_--){ RD(n); Matrix ans,tmp[11]; ans.id(); for(int i = 0;i < n;++i){ scanf("%lf%lf%lf", &x, &y, &r); tmp[i].init(); ans = ans*tmp[i]; } double cosr = ans.v[0][0],sinr = ans.v[0][1]; r = atan2(sinr,cosr); if(r < 0) r += 2*pi; double c1 = ans.v[2][0],c2 = ans.v[2][1]; double y = (c2*(cosr - 1) - sinr*c1)/(-sinr*sinr-(1-cosr)*(1-cosr)), x = (c1*(1-cosr) - c2*sinr)/((1-cosr)*(1-cosr) + sinr*sinr); printf("%.10lf %.10lf %.10lf\n", x, y, r); } return 0; }