设为首页 加入收藏

TOP

矩阵乘法(六):几何变换(六)
2019-09-07 07:09:36 】 浏览:182
Tags:矩阵 乘法 几何 变换
2] = (1-cos(d))*y*y + cos(d); tmp.mat[2][3] = (1-cos(d))*y*z - x*sin(d); tmp.mat[3][1] = (1-cos(d))*x*z - y*sin(d); tmp.mat[3][2] = (1-cos(d))*y*z + x*sin(d); tmp.mat[3][3] = (1-cos(d))*z*z + cos(d); tmp.mat[4][4]=1; p=matMul(tmp,p,4); return p; } Matrix work(int n) { Matrix p; int i; double x,y,z,d; memset(p.mat,0,sizeof(p.mat)); for (i=1;i<=4;i++) p.mat[i][i]=1; char s[100]; while (1) { scanf("%s", s); if (strcmp(s,"translate")==0) { scanf("%lf%lf%lf",&x,&y,&z); p=translate(p,x,y,z); continue; } if (strcmp(s,"scale")==0) { scanf("%lf%lf%lf",&x,&y,&z); p=scale(p,x,y,z); continue; } if (strcmp(s,"rotate")==0) { scanf("%lf%lf%lf%lf",&x,&y,&z,&d); p=rotate(p,x,y,z,d); continue; } if (strcmp(s,"repeat")==0) { int n1; scanf("%d", &n1); p = matMul(work(n1),p,4); } if (strcmp(s,"end")==0) { p=quickMatPow(p,4,n); return p; } } } int main() { int n,i; Matrix p; double a[4]; double tx,ty,tz,td; while(scanf("%d", &n) && n!=0) { p=work(1); while (n--) { scanf("%lf%lf%lf",&a[1],&a[2],&a[3]); tx=a[1],ty=a[2],tz=a[3],td=1; for (i=1; i<=4;i++) { a[i] =p.mat[i][1]*tx +p.mat[i][2]*ty +p.mat[i][3]*tz + p.mat[i][4]*td; if (fabs(a[i])<eps) a[i]=0.0; } printf("%.2lf %.2lf %.2lf\n",a[1],a[2],a[3]); } printf("\n"); } return 0; }
首页 上一页 3 4 5 6 下一页 尾页 6/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇在C++工程上添加CUDA编译环境 下一篇又是a+b

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目