nyoj 298 点的变换

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;
#define PI acos(-1.0)

const int MAXN = 10010;
struct Node
{
double x, y;
}iPoint[MAXN];

struct Matrix
{
double iMatrix[3][3];
};

Matrix Multi_Mattrix(Matrix a, Matrix b)
{
Matrix c;

int i, j, k;
for(i = 0; i < 3; ++i)
{
for(j = 0; j < 3; ++j)
{
c.iMatrix[i][j] = 0;
for(k = 0; k < 3; ++k)
c.iMatrix[i][j] += a.iMatrix[i][k] * b.iMatrix[k][j];
}
}
return c;
}

int main()
{
int n, m, i;
Matrix iMove, iXSymmetry, iYSymmetry, iEnlarge, iRotate;

scanf("%d%d", &n, &m);
for(i = 0; i < n; ++i)
scanf("%lf%lf", &iPoint[i].x, &iPoint[i].y);

memset(iMove.iMatrix, 0, sizeof(iMove.iMatrix));//平移
memset(iXSymmetry.iMatrix, 0, sizeof(iXSymmetry.iMatrix));//关于x轴对称
memset(iYSymmetry.iMatrix, 0, sizeof(iYSymmetry.iMatrix));//关于y轴对称
memset(iEnlarge.iMatrix, 0, sizeof(iEnlarge.iMatrix));//缩放
memset(iRotate.iMatrix, 0, sizeof(iRotate.iMatrix));//旋转
iMove.iMatrix[0][0] = iMove.iMatrix[1][1] = iMove.iMatrix[2][2] = 1;
iXSymmetry.iMatrix[0][0] = iXSymmetry.iMatrix[2][2] = 1; iXSymmetry.iMatrix[1][1] = -1;
iYSymmetry.iMatrix[1][1] = iYSymmetry.iMatrix[2][2] = 1; iYSymmetry.iMatrix[0][0] = -1;
iEnlarge.iMatrix[2][2] = iRotate.iMatrix[2][2] = 1;

Matrix tmp;
memset(tmp.iMatrix, 0, sizeof(tmp.iMatrix));
tmp.iMatrix[0][0] = tmp.iMatrix[1][1] = tmp.iMatrix[2][2] = 1;
char c;
double x, y;
while(m--)
{
getchar();
scanf("%c", &c);

switch(c)
{
case 'M':
scanf("%lf %lf", &x, &y);
iMove.iMatrix[0][2] = x;
iMove.iMatrix[1][2] = y;
tmp = Multi_Mattrix(iMove, tmp);
break ;
case 'X':
tmp = Multi_Mattrix(iXSymmetry, tmp);
break ;
case 'Y':
tmp = Multi_Mattrix(iYSymmetry, tmp);
break ;
case 'S':
scanf("%lf", &x);
iEnlarge.iMatrix[0][0] = iEnlarge.iMatrix[1][1] = x;
tmp = Multi_Mattrix(iEnlarge, tmp);
break ;
case 'R':
scanf("%lf", &x);
y = x/180 * PI;
iRotate.iMatrix[0][0] = iRotate.iMatrix[1][1] = cos(y);
iRotate.iMatrix[0][1] = -sin(y);
iRotate.iMatrix[1][0] = sin(y);
tmp = Multi_Mattrix(iRotate, tmp);
break ;
default:
break ;
}
}
Matrix res;
for(i = 0; i < n; ++i)
{
memset(res.iMatrix, 0, sizeof(res.iMatrix));

res.iMatrix[0][0] = iPoint[i].x;
res.iMatrix[1][0] = iPoint[i].y;
res.iMatrix[2][0] = 1;
res = Multi_Mattrix(tmp, res);
printf("%.1lf %.1lf\n", res.iMatrix[0][0], res.iMatrix[1][0]);
}
return 0;
}