📜  二维变换的矩阵表示

📅  最后修改于: 2020-12-20 09:48:51             🧑  作者: Mango

二维变换的矩阵表示

实施二维转换的程序:

#include
#include
#include
#include
#include
class trans
{
    float x[20],y[20],xm,ym,ref[2][2],shx,shy;
    int i,j,k,n;
    float sx,sy,tx,ty,ang;
    int gd,gm;
    float xtmp [20],ytmp[20];
    public:
    void takeinput();
    void menu();
    void graphmode();
    void mapgraph();
    void plotint();
    void translate();
    void scale();
    void rotate();
    void reflect();
    void shear();
    void plotfinal();
};
int ch;
void trans::takeinput()
{
    cout<<"ENTER THE NO OF VERTICES\n";
    cin>>n;
    for (i=0;i>x[i]>>y[i];
    }
    clrscr();
}
void trans::menu()
{
    int kk;
    cout<<"\n1:TRANSLATION";
    cout<<"\n2:SCALING";
    cout<<"\n3:ROTATION";
    cout<<"\n4:REFLECTION";
    cout<<"\n5:SHEARING";
    cout<<"\n6:EXIT";
    cin>>ch;
    switch (ch)
    {
        case1:
            cout<<"\n ENTER TX AND TY";
            cin>>tx>>ty;
            break;
        case2:
            cout<<"\n ENTER SX AND SY";
            cin>>sx>>sy;
            break;
        case3:
            cout<<"\n ENTER ANGLE OF ROTATION";
            cin>>ang;
            break;
        case4:
            cout<<"\n REFLECTION MENU";
            cout<<"\n 1:X-PLANE";
            cout<<"\n 2: Y-PLANE";
            cout<<"\n 3: ORIGIN";
            cout<<"\n 4: Y=X PLANE";
            cout<<"\n 5: Y=-X PLANE";
            cout<<"\n ENTER YOUR CHOICE";
            cin>>kk;
            switch (kk)
            {
                case1:
                         ref [0][0] =1;
                    ref [0][1]=0;
                    ref [1][0]=0;
                    ref [1][1]=1;
                    break;
                case2:
                    ref [0][0]= -1;
                    ref [0][1]=0;
                    ref [1][0]=0;
                    ref [1][1]=1;
                    break;
                case3:
                    ref [0][0]=-1;
                    ref [0][1]=0;
                    ref [1][0]=0;
                    ref [1][1]=1;
                    break;
                case4:
                    ref [0][0]=0;
                    ref [0][1]=1;
                    ref [1][0] =1;
                    ref [1][1]=0;
                    break;
                case5:
                    ref [0][0]=0;
                    ref [0][1]=1;
                    ref [1][0]=1;
                    ref [1][1]=0;
                    break;
        case5:
            cout<< "\n SHEARING MENU";
            cout<<"\n 1:X-DIR\n 2: Y-DIR \n 3: X-Y DIR\n ENTER YOUR                 CHOICE";
            cin>>kk;
            switch (kk)
            {
                case1:
                    cout<<"\n ENTER SHX";
                    cin>> shx;
                    ref[0][0] =1;
                    ref [0][1]=0;
                    ref [1][0]=shx;
                    ref [1][1]=1;
                    break;
                case2:
                    cout<< "\n ENTER SHY";
                    cin>>shy;
                    ref [0][0]=1;
                    ref [0][1]=shy;
                    ref [1][0]=0;
                    ref [1][1] =1;
                    break;
                case3:
                    cout<<"\n ENTER SHX";
                    cin >> shx;
                    cout<<"\n ENTER SHY";
                    cin>> shy;
                    ref [0][0] =1;
                    ref [0][1] =shy;
                    ref [1][0] =shx;
                    ref [1][1] =1;
                    break;
                }
                break;
            }
        }
    void trans::graphmode()
    {
        gd=DETECT;
        initgraph (&gd, &gm, "");
    }
    void trans::mapgraph()
    {
        xm=getmaxx ()/2;
        ym=getmaxy ()/2;
        line (xm,0,xm,2*ym);
        line (0,ym,2 * xm,ym);
    }
    void trans::plotint()
    {
        for(i=0;i

输出:

翻译

1:翻译
2:缩放
3:旋转
4:反射
5:剪切
6:退出
输入您的选择4
反射菜单
1:x-平面
2:y平面
3:起源
4:y 10="" 10<="" 10
输入三个坐标
40="" 10
输入两个坐标
30="" 1:翻译
2:缩放
3:旋转
4:反射
5:剪切
6:退出
输入您的选择1
输入tx和ty="" 1:翻译
2:缩放
3:旋转
4:反射
5:剪切
6:退出
输入您的选择5
剪切菜单
1:x-dir
="" 20
="" 20
输入四个坐标
35="" 2:y-dir
输入您的选择3

输入shx="" 30
输入5个坐标
15="" 5
输入害羞5
输入无广告
5
输入1个坐标
10="" =="" p="" x平面
5:y="-X平面
输入您的选择4
">


2:缩放
3:旋转
4:反射
5:剪切
6:退出
输入您的选择4
反射菜单
1:x-平面
2:y平面
3:起源
4:y>