鞍山网赛-矩阵的旋转平移

           B. Rotate
[Problem Description]
Noting is more interesting than rotation!
Your little sister likes to rotate things. To put it easier to analyze, your sister makes n rotations. In the 
i-th time, she makes everything in the plane rotate counter-clockwisely around a point ai by a radian 
of pi.
Now she promises that the total effect of her rotations is a single rotation around a point A by radian 
P (this means the sum of pi is not a multiplier of 2π).
Of course, you should be able to figure out what is A and P :).
[Input Format]
The first line contains an integer T, denoting the number of the test cases.
For each test case, the first line contains an integer n denoting the number of the rotations. Then n
lines follows, each containing 3 real numbers x, y and p, which means rotating around point (x, y) 
counter-clockwisely by a radian of p.
We promise that the sum of all p's is differed at least 0.1 from the nearest multiplier of 2π.
T<=100. 1<=n<=10. 0<=x, y<=100. 0<=p<=2π.
[Output Format]
For each test case, print 3 real numbers x, y, p, indicating that the overall rotation is around (x, y) 
counter-clockwisely by a radian of p. Note that you should print p where 0<=p<2π.
Your answer will be considered correct if and only if for x, y and p, the absolute error is no larger 
than 1e-5.
[Sample Input]
1
3
0 0 1
1 1 1
2 2 1
[Sample Output]
1.8088715944 0.1911284056 3.0000000000





样例中的三个矩阵相乘,重点学习了矩阵的乘法

把思路理清来写程序

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;
#define   pi  (acos(-1.0))
void matx (double b[3][3], double a[3][3], double c[3][3])
{
    for(int i=0; i<3; ++i){
        for(int j=0; j<3; ++j)
        {
            double sum = 0;
            for(int k=0; k<3; ++k)
                sum += a[i][k] * b[k][j];
            c[i][j] = sum;
        }
    }
}
int creat(double  a[3][3],double x,double y,double th)
{
    a[0][0]=cos(th);
    a[0][1]=-sin(th);
    a[0][2]=x-x*cos(th)+y*sin(th);
    a[1][0]=sin(th);
    a[1][1]=cos(th);
    a[1][2]=y-x*sin(th)-y*cos(th);
    a[2][0]=0;
    a[2][1]=0;
    a[2][2]=1;
return 0;
}
int main()
{
    int t,i,n,j;
    double   poi[13][2],jd[13],a[3][3],b[3][3],c[3][3];
    cin>>t;
    while(t--)
    {
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            scanf("%lf%lf%lf",&poi[i][0],&poi[i][1],&jd[i]);
        }
        creat(a,poi[1][0],poi[1][1],jd[1]);
        for(i=2;i<=n;i++)
        {
           creat(b,poi[i][0],poi[i][1],jd[i]);
           matx(a,b,c);
           for(int i1=0;i1<3;i1++)
            for(int j1=0;j1<3;j1++)
            a[i1][j1]=c[i1][j1];
        }
        double  x0,y0,jd0;
        jd0=acos(a[0][0]);
        if(a[1][0]<0) jd0=2*pi-jd0;
        /*for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++)
            {
                cout<<a[i][j]<<"   ";
            }
            cout<<endl;
        }*/

        x0=(a[0][2]*(1-a[0][0])-a[1][0]*a[1][2])/((1-a[0][0])*(1-a[0][0])+a[1][0]*a[1][0]);
        y0=(a[1][2]*(1-a[0][0])-a[0][1]*a[0][2])/((1-a[0][0])*(1-a[0][0])+a[1][0]*a[1][0]);
printf("%.10lf %.10lf %.10lf\n",x0,y0,jd0);
      }
 return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值