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; }
|