UNKNOWN //************************************** // Name: Two Deimensional 2D Basic Transformation // Description:To Perform 2D basic transformations on objects in C. // By: Rekha Ram Chaudhary // // // Inputs:None // // Returns:None // //Assumes:None // //Side Effects:None //This code is copyrighted and has limited warranties. //Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.13853/lngWId.3/qx/vb/scripts/ShowCode.htm //for details. //************************************** #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> #include<math.h> #include<stdlib.h> void menu(); void input(); void input1(); void output(); void output1(); void translation(); void rotation(); void scaling(); int a[10][10],b[10][10],b1[10][10],diff,i,j,x,option,temp,angle,tx,ty,fx,fy,sh,k,n,axis,y; float sx,sy; void menu() { printf("menu\n"); printf("0.draw\n"); printf("1.Translation\n"); printf("2.rotation\n"); printf("3.scaling\n"); printf("4.exit\n"); printf("enter the choice:"); scanf("%d",&option); switch(option) { case 0: input(); menu(); break; case 1: translation(); break; case 2: rotation(); break; case 3: scaling(); break; case 4: exit(0); break; } input(); } void input() { printf("enter the number of vertices:" ); scanf("%d",&n); for(i=0;i<n;i++) { printf("enter the coordinates:"); scanf("%d%d%d%d",&a[i][0],&a[i][1],&a[i+1][0],&a[i+1][1]); } } void output() { cleardevice(); for(i=0;i<n;i++) { line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]); } for(i=0;i<n;i++) { b[i][0]=0; b[i][1]=0; }} void input1() { cleardevice(); for(i=0;i<n;i++) { line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]); } } void output1() { cleardevice(); for(i=0;i<n;i++) { line(b[i][0],b[i][1],b[i+1][0],b[i+1][1]); } } void translation() { output(); printf("enter the tranformation vertex tx,ty:\n"); scanf("%d%d",&tx,&ty); for(i=0;i<=n;i++) { b[i][0]=a[i][0]+tx; b[i][1]=a[i][1]+ty; } output1(); delay(10); menu(); } void rotation() { output(); printf("enter the rotating angle:"); scanf("%d",&y); printf("enter the pivot point:"); scanf("%d%d",&fx,&fy); k=(y*3.14)/180; for(i=0;i<=n;i++) { b[i][0]=fx+(a[i][0]-fx)*cos(y)+(a[i][1]-fy)*sin(y); b[i][1]=fy+(a[i][0]-fx)*sin(y)-(a[i][1]-fy)*cos(y); } output1(); delay(10); menu(); } void scaling() { output(); printf("enter the scaling factor\n"); scanf("%f%f",&sx,&sy); printf("enter the fixed point:"); scanf("%d%d",&fx,&fy); for(i=0;i<=n;i++) { b[i][0]=a[i][0]*sx+fy*(1-sx); b[i][1]=a[i][1]*sy+fy*(1-sy); } output1(); delay(10); menu(); } void main() { int gd=DETECT,gm; initgraph(&gd,&gm,"c:\\tc\\bgi"); menu(); getch(); }