设为首页 加入收藏

TOP

矩阵乘法(六):几何变换(二)
2019-09-07 07:09:36 】 浏览:192
Tags:矩阵 乘法 几何 变换
nbsp;        for (i=1 ;i<=n ; i++)
                if (a.mat[i][k]!=0)
                     for (j = 1 ;j<=n ;j++)
                        c.mat[i][j] = (c.mat[i][j] + a.mat[i][k] * b.mat[k][j]) ;
      return c;
}
int main()
{
      char ch ;
      Point p[MAXN];
      Matrix ans,temp;
      double a ;
      int n,m,i,j;
      scanf("%d%d",&n,&m);
      for (i=0 ;i<n;i++)
      scanf("%lf%lf" ,&p[i].x ,&p[i].y);
      memset(ans.mat,0,sizeof(ans.mat));      // 初始为单位阵
       ans.mat[1][1]=ans.mat[2][2]=ans.mat[3][3]=1;
       for (i=0 ;i<m;i++)
       {
              memset(temp.mat,0,sizeof(temp.mat)); // 初始为单位阵
              temp.mat[1][1]=temp.mat[2][2]=temp.mat[3][3]=1;
              getchar();
              scanf("%c",&ch);
              if (ch == 'M')            // 平移
                     scanf("%lf%lf" ,&temp.mat[1][3] ,&temp.mat[2][3]);
              else if (ch == 'X')     // 相对X轴上下翻转
                     temp.mat[2][2]=-1;
              else if (ch == 'Y')     // 相对于Y轴左右翻转
                     temp.mat[1][1] = -1 ;
              else if (ch == 'S')      // 坐标放大P倍
               {
                     scanf("%lf" ,&temp.mat[1][1]) ;
                     temp.mat[2][2] = temp.mat[1][1] ;
               }
               else if (ch == 'R')    // 相对坐标原点逆时针旋转一定的角度A
               {
                     scanf("%lf" ,&a) ;
                     a = (a*PI)/180.0 ;
                     temp.mat[1][1] = temp.mat[2][2] = cos(a) ;
                     temp.mat[1][2] = -sin(a) ;
                     temp.mat[2][1] = sin(a) ;
              }
             ans=matMul(temp,ans,3);
      }
      for (i=0 ;i<n ; i++)
      {
             for (j=1 ;j<=2; j++)
        &nb
首页 上一页 1 2 3 4 5 6 下一页 尾页 2/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇在C++工程上添加CUDA编译环境 下一篇又是a+b

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目