hdu 4998 矩阵表示旋转
来源:互联网 发布:合作医疗软件 编辑:程序博客网 时间:2024/06/06 09:34
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;}
0 0
- hdu 4998 矩阵表示旋转
- 关于旋转矩阵的表示
- 旋转矩阵的表示方法
- HDU - 旋转矩阵
- 怎么将变换矩阵分解为缩放和旋转,尽量不用矩阵表示
- 旋转矩阵
- 矩阵旋转
- 旋转矩阵
- 旋转矩阵
- 旋转矩阵
- 旋转矩阵
- 矩阵旋转
- 旋转矩阵
- 旋转矩阵
- 矩阵旋转
- 矩阵 旋转
- 矩阵旋转
- 旋转矩阵
- Laravel教程:laravel 4安装及入门
- 【Unity3D_Shader】图形学相关
- JVM组成部分以及内存模型
- Android动画之Drawable Animation
- CentOS 6.5基于DHCP的PXE自动化安装系统详解
- hdu 4998 矩阵表示旋转
- rsa加密算法
- 未来社交网站:15秒内让你闻名全球 虚拟现实与社交网络融合
- java+jasperreport开发web报表
- 渣基础:比照Hawstein学Cracking the coding interview(4)
- 大数据学习路线
- mysql 常见问题解决
- 解决MySQL创建外键时ERROR 1005, errorno:150的错误
- LeetCode: Remove Duplicates from Sorted List II