Pages

Translation,Rotation,Scallig

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
#include<process.h>
# define pi 3.14
void translation(int[]);
void rotation(int[]);
void scalling(int[]);
int vr;
void main()
    {
    int gmode,gdrive=DETECT;
    int i,poly[10],ch;
    clrscr();
    initgraph(&gdrive,&gmode,"C:\\TC\\BGI");
    printf("ENTER NUMBER  OF POLYGON VECTOR:");
    scanf("%d",&vr);
    for(i=0;i<2*vr;i+=2)
        {
        printf("ENTER VECTOR %d :",i/2+1);
        scanf("%d %d",&poly[i],&poly[i+1]);
        }
    poly[i] = poly[0];
    poly[i+1] = poly[1];
    drawpoly(vr+1,poly);
    while(1)
    {
    printf("1.TRANSLATION:\n");
    printf("2.ROTATION:\n");
    printf("3.SCALLING:\n");
    printf("4.EXIT:\n");
    printf("ENTER YOUR CHOICE:");
    scanf("%d",&ch);
    switch(ch)
        {
        case 1:
            translation(poly);
            break;
        case 2:
            rotation(poly);
            break;
        case 3:
            scalling(poly);
            break;
        case 4:
            exit(0);
        default:
            printf("INVALID CHOICE......\n");
        }
    }
    getch( );
    closegraph();
    }
void translation(int poly[])
    {
    int i,tx,ty;
    printf("ENTER TRANSLATION VECTOR:");
    scanf("%d %d",&tx,&ty);
    for(i=0;i<2*vr;i+=2)
        {
        poly[i]+=tx;
        poly[i+1]+=ty;
        }
    poly[i] = poly[0];
    poly[i+1] = poly[1];
    drawpoly(vr+1,poly);
    }
void rotation(int poly[])
    {
    int i,thita,t1,t2;
    printf("ENTER ROTATION ANGLE:");
    scanf("%d",&thita);
    for(i=0;i<2*vr;i+=2)
        {
        t1=poly[i]*cos(thita*pi/180)-poly[i+1]*sin(thita*pi/180);
        t2=poly[i]*sin(thita*pi/180)+poly[i+1]*cos(thita*pi/180);
        poly[i]=t1;
        poly[i+1]=t2;
        }
    poly[i] = poly[0];
    poly[i+1] = poly[1];
    drawpoly(vr+1,poly);
    }
void scalling(int poly[])
    {
    float sx,sy;
    int i,xf,yf;
    printf("ENTER SCALLING CORDINATE");
    scanf("%d %d",&xf,&yf);
    printf("ENTER SCALLING VECTOR:");
    scanf("%f %f",&sx,&sy);
    for(i=0;i<2*vr;i+=2)
        {
        poly[i]=poly[i]*sx+xf*(1-sx);
        poly[i+1]=poly[i+1]*sy+yf*(1-sy);
        }
    poly[i] = poly[0];
    poly[i+1] = poly[1];
    drawpoly(vr+1,poly);
    }