Sunday, July 29, 2012

TWO DIMENSIONAL [ 2D ] TRANSFORMATION TO PERFORM TRANSLATION ROTATION SCALING SHEARING REFLECTION on tc



Procedure

TWO DIMENSIONAL [ 2D ] TRANSFORMATION TO PERFORM TRANSLATION ROTATION SCALING SHEARING REFLECTION

 

Run in this order ::: (*_*)

1. Translation

2. Rotation

3. Scaling

4. Shearing

5. Reflection

 

 

//Hackerx

# include<graphics.h>

# include<stdio.h>

# include<conio.h>

# include<math.h>

void main()

{

                int gd=DETECT,gm,i,j,k,ch;

                float tx,ty,x,y,ang,n,temp;

                float a[5][3],si,co,b[5][3],c[5][3];

                initgraph(&gd,&gm,"e:\\tcpp\\bgi");

                n=4;

                a[0][0]=0;

                a[0][1]=0;

                a[1][0]=100;

                a[1][1]=0;

                a[2][0]=100;

                a[2][1]=100;

                a[3][0]=0;

                a[3][1]=100;

                a[4][0]=0;

                a[4][1]=0;

                while(1)

                {

                                cleardevice();

                                gotoxy(1,8);

                                printf("\n\t******** Program to perform 2-D Transformations ********");

                                printf("\n\t\t\t 1. Accept the polygon");

                                printf("\n\t\t\t 2. Perform translation");

                                printf("\n\t\t\t 3. Perform scaling");

                                printf("\n\t\t\t 4. Perform rotation");

                                printf("\n\t\t\t 5. Perform reflection");

                                printf("\n\t\t\t 6. Perform shearing");

                                printf("\n\t\t\t 7. Exit");

                                printf("\n\t\t\t Enter your choice::");

                                scanf("%d",&ch);

                                switch(ch)

                                {

                                                case 1: cleardevice();

                                                                                gotoxy(1,1);

                                                                                printf("\n\tEnter no of points.:");

                                                                                scanf("%f",&n);

                                                                                for(i=0;i<n;i++)

                                                                                {

                                                                                                printf("\n\t Enter x,y co-ordinates for %d::",i+1);

                                                                                                scanf("%f %f",&a[i][0],&a[i][1]);

                                                                                }

                                                                                a[i][0]=a[0][0];

                                                                                a[i][1]=a[0][1];

                                                                                cleardevice();

                                                                                for(i=0;i<n;i++)

                                                                                line(320+a[i][0],240-a[i][1],320+a[i+1][0],240-a[i+1][1]);

                                                                                line(0,240,639,240);

                                                                                line(320,0,320,479);

                                                                                getch();

                                                                                break;

                                                case 2: cleardevice();

                                                                                for(i=0;i<n;i++)

                                                                                line(320+a[i][0],240-a[i][1],320+a[i+1][0],240-a[i+1][1]);

                                                                                line(0,240,639,240);

                                                                                line(320,0,320,479);

                                                                                gotoxy(1,1);

                                                                                printf("Enter translation vectors tx and ty\n\t");

                                                                                scanf("%f %f",&x,&y);

                                                                                cleardevice();

                                                                                for(i=0;i<n;i++)

                                                                                line(320+a[i][0]+x,240-(a[i][1]+y),320+a[i+1][0]+x,240-(a[i+1][1]+y));

                                                                                line(0,240,639,240);

                                                                                line(320,0,320,479); //Hackerx

                                                                                getch();

                                                                                break;

                                                case 3: cleardevice();

                                                                                for(i=0;i<n;i++) line(320+a[i][0],240-a[i][1],320+a[i+1][0],240-a[i+1][1]);

                                                                                line(0,240,639,240);

                                                                                line(320,0,320,479);

                                                                                gotoxy(1,1);

                                                                                printf("Enter scaling vectors tx and ty\n\t");

                                                                                scanf("%f %f",&x,&y);

                                                                                if(x==0)

                                                                                                x=1;

                                                                                                if(y==0)

                                                                                                                y=1;

                                                                                                                cleardevice();

                                                                                                                for(i=0;i<n;i++)

                                                                                                                line(320+(a[i][0]*x),240-(a[i][1]*y),320+(a[i+1][0]*x),240-(a[i+1][1]*y));

                                                                                                                line(0,240,639,240);

                                                                                                                line(320,0,320,479);

                                                                                                                getch();

                                                                                                                break;

                                                case 4: cleardevice();

                                                                                for(i=0;i<n;i++)

                                                                                line(320+a[i][0],240-a[i][1],320+a[i+1][0],240-a[i+1][1]);

                                                                                line(0,240,639,240);

                                                                                line(320,0,320,479);

                                                                                gotoxy(1,1);

                                                                                printf("Enter the angle of rotation\n\t");

                                                                                scanf("%f",&ang);

                                                                                ang=ang*0.01745;

                                                                                gotoxy(1,3);

                                                                                printf("Enter point of rotation\n\t");

                                                                                scanf("%f %f",&x,&y);

                                                                                gotoxy(1,5);

                                                                                printf("1.clockwise 2.anticlockwise\n\t");

                                                                                scanf("%d",&k);

                                                                                si=sin(ang);

                                                                                co=cos(ang);

                                                                                for(i=0;i<n+1;i++)

                                                                                {

                                                                                                c[i][0]=a[i][0];

                                                                                                c[i][1]=a[i][1];

                                                                                                c[i][2]=1;

                                                                                }

                                                                                b[0][0]=co;

                                                                                b[0][1]=si;

                                                                                b[0][2]=0;

                                                                                b[1][0]=(-si);

                                                                                b[1][1]=co;

                                                                                b[1][2]=0;

                                                                                b[2][0]=(-x*co)+(y*si)+x;

                                                                                b[2][1]=(-x*si)-(y*co)+y;

                                                                                b[2][2]=1;

                                                                                if(k==1)

                                                                                {             

                                                                                                b[0][1]=(-si);

                                                                                                b[1][0]=(si);

                                                                                                b[2][0]=(-x*co)-(y*si)+x;

                                                                                                b[2][1]=(-x*si)+(y*co)+y;

                                                                                }

                                                                                for(i=0;i<n+1;i++)

                                                                                {

                                                                                                for(j=0;j<3;j++)

                                                                                                                {

                                                                                                                                a[i][j] = 0 ;

                                                                                                                                                for(k=0;k<3;k++)

                                                                                                                                                                a[i][j] = a[i][j] + c[i][k] * b[k][j] ;

                                                                                                                }

                                                                                } cleardevice();

                                                                                for(i=0;i<n;i++)

                                                                                line(320+a[i][0],240-a[i][1],320+a[i+1][0],240-a[i+1][1]);

                                                                                line(0,240,639,240);

                                                                                line(320,0,320,479);

                                                                                getch();

                                                                                break;

                                                case 5: cleardevice();

                                                                                for(i=0;i<n;i++)

                                                                                line(320+a[i][0],240-a[i][1],320+a[i+1][0],240-a[i+1][1]);

                                                                                line(0,240,639,240);

                                                                                line(320,0,320,479);

                                                                                gotoxy(1,1);

                                                                                printf("\n1.Reflection about Y-axis");

                                                                                printf("\n2.Reflection about X-axis");

                                                                                printf("\n3.Reflection about origin");

                                                                                printf("\n4.Reflection about line y=x");

                                                                                printf("\n5.Reflection about line y=-x");

                                                                                printf("\nEnter your choice:");

                                                                                scanf("%d",&ch);

                                                                                switch(ch)

                                                                                                {

                                                                                                                case 1:  for(i=0;i<n+1;i++)

                                                                                                                                                a[i][0]=a[i][0]*(-1); /* Plot the polygon */

                                                                                                                                                cleardevice();

                                                                                                                                                for(i=0;i<n;i++)

                                                                                                                                                line(320+a[i][0],240-a[i][1],320+a[i+1][0],240-a[i+1][1]);

                                                                                                                                                line(0,240,639,240);

                                                                                                                                                line(320,0,320,479);

                                                                                                                                                getch();

                                                                                                                                                break;

                                                                                                                case 2: for(i=0;i<n+1;i++)

                                                                                                                                                a[i][1]=a[i][1]*(-1);

                                                                                                                                                cleardevice();

                                                                                                                                                for(i=0;i<n;i++)

                                                                                                                                                line(320+a[i][0],240-a[i][1],320+a[i+1][0],240-a[i+1][1]);

                                                                                                                                                line(0,240,639,240);

                                                                                                                                                line(320,0,320,479);

                                                                                                                                                getch();

                                                                                                                                                break;

                                                                                                                case 3: for(i=0;i<n+1;i++)

                                                                                                                                                {

                                                                                                                                                                a[i][1]=a[i][1]*(-1);

                                                                                                                                                                a[i][0]=a[i][0]*(-1);

                                                                                                                                                }

                                                                                                                                                cleardevice();

                                                                                                                                                for(i=0;i<n;i++)

                                                                                                                                                line(320+a[i][0],240-a[i][1],320+a[i+1][0],240-a[i+1][1]);

                                                                                                                                                line(0,240,639,240);

                                                                                                                                                line(320,0,320,479);

                                                                                                                                                getch();

                                                                                                                                                break;

                                                                                                                case 4: for(i=0;i<n+1;i++)

                                                                                                                                                {

                                                                                                                                                                temp=a[i][0];

                                                                                                                                                                a[i][0]=a[i][1];

                                                                                                                                                                a[i][1]=temp;

                                                                                                                                                }

                                                                                                                                                cleardevice();

                                                                                                                                                for(i=0;i<n;i++)

                                                                                                                                                line(320+a[i][0],240-a[i][1],320+a[i+1][0],240-a[i+1][1]);

                                                                                                                                                line(0,240,639,240);

                                                                                                                                                line(320,0,320,479);

                                                                                                                                                line(0,479,639,0);

                                                                                                                                                getch();

                                                                                                                                                break;

                                                                                                                case 5: for(i=0;i<n+1;i++)

                                                                                                                                                {

                                                                                                                                                                temp=a[i][0];

                                                                                                                                                                a[i][0]=a[i][1];

                                                                                                                                                                a[i][1]=temp;

                                                                                                                                                }

                                                                                                                                                for(i=0;i<n+1;i++)

                                                                                                                                                {

                                                                                                                                                                a[i][1]=a[i][1]*(-1);

                                                                                                                                                                a[i][0]=a[i][0]*(-1);

                                                                                                                                                }

                                                                                                                                                cleardevice();

                                                                                                                                                for(i=0;i<n;i++)

                                                                                                                                                line(320+a[i][0],240-a[i][1],320+a[i+1][0],240-a[i+1][1]);

                                                                                                                                                line(0,240,639,240);

                                                                                                                                                line(320,0,320,479);

                                                                                                                                                line(0,0,639,479);

                                                                                                                                                getch();

                                                                                                                                                break;

                                                                                                                default: break;

                                                                                                }

                                                                                                break;

                                                                                                                case 6: cleardevice();

                                                                                                                                                for(i=0;i<n;i++)

                                                                                                                                                line(320+a[i][0],240-a[i][1],320+a[i+1][0],240-a[i+1][1]);

                                                                                                                                                line(0,240,639,240);

                                                                                                                                                line(320,0,320,479);

                                                                                                                                                gotoxy(1,1);

                                                                                                                                                printf("\n1.X shear with y reference line");

                                                                                                                                                printf("\n2.Y shear with x reference line");

                                                                                                                                                printf("\nEnter your choice:");

                                                                                                                                                scanf("%d",&ch);

                                                                                                                                                switch(ch)

                                                                                                                                                                {

                                                                                                                                                                                case 1: printf("\nEnter the x-shear parameter value:");

                                                                                                                                                                                                                                scanf("%f",&temp);

                                                                                                                                                                                                                                printf("\nEnter the yref line");

                                                                                                                                                                                                                                scanf("%f",&ty);

                                                                                                                                                                                                                                b[0][0]=1;

                                                                                                                                                                                                                                b[0][1]=0;

                                                                                                                                                                                                                                b[0][2]=0;

                                                                                                                                                                                                                                b[1][0]=temp;

                                                                                                                                                                                                                                b[1][1]=1;

                                                                                                                                                                                                                                b[1][2]=0;

                                                                                                                                                                                                                                b[2][0]=(-temp)*(ty);

                                                                                                                                                                                                                                b[2][1]=0;

                                                                                                                                                                                                                                b[2][2]=1;

                                                                                                                                                                                                                                for(i=0;i<n+1;i++)

                                                                                                                                                                                                                                a[i][2]=1;

                                                                                                                                                                                                                                for(i=0;i<n+1;i++)

                                                                                                                                                                                                                                                {

                                                                                                                                                                                                                                                                for(j=0;j<3;j++)

                                                                                                                                                                                                                                                                                {

                                                                                                                                                                                                                                                                                                c[i][j] = 0 ;

                                                                                                                                                                                                                                                                                                for(k=0;k<3;k++)

                                                                                                                                                                                                                                                                                                                c[i][j] = c[i][j] + a[i][k] * b[k][j] ;

                                                                                                                                                                                                                                                                                }

                                                                                                                                                                                                                                                }

                                                                                                                                                                                                                                                cleardevice();

                                                                                                                                                                                                                                                for(i=0;i<n;i++)

                                                                                                                                                                                                                                                line(320+c[i][0],240-c[i][1],320+c[i+1][0],240-c[i+1][1]);

                                                                                                                                                                                                                                                line(0,240,639,240);

                                                                                                                                                                                                                                                line(320,0,320,479);

                                                                                                                                                                                                                                                getch();

                                                                                                                                                                                                                                                break;

                                                                                                                                                                                case 2: printf("\nEnter the y-shear parameter value:");

                                                                                                                                                                                                                                scanf("%f",&temp);

                                                                                                                                                                                                                                printf("\nEnter the xref line");

                                                                                                                                                                                                                                scanf("%f",&tx);

                                                                                                                                                                                                                                b[0][0]=1;

                                                                                                                                                                                                                                b[0][1]=temp;

                                                                                                                                                                                                                                b[0][2]=0;

                                                                                                                                                                                                                                b[1][0]=0;

                                                                                                                                                                                                                                b[1][1]=1;

                                                                                                                                                                                                                                b[1][2]=0;

                                                                                                                                                                                                                                b[2][0]=0;

                                                                                                                                                                                                                                b[2][1]=(-temp)*(tx);

                                                                                                                                                                                                                                b[2][2]=0;

                                                                                                                                                                                                                                for(i=0;i<n+1;i++)

                                                                                                                                                                                                                                a[i][2]=1;

                                                                                                                                                                                                                                for(i=0;i<n+1;i++)

                                                                                                                                                                                                                                                {

                                                                                                                                                                                                                                                                for(j=0;j<3;j++)

                                                                                                                                                                                                                                                                                {

                                                                                                                                                                                                                                                                                                c[i][j] = 0 ;

                                                                                                                                                                                                                                                                                                for(k=0;k<3;k++)

                                                                                                                                                                                                                                                                                                                c[i][j] = c[i][j] + a[i][k] * b[k][j] ;

                                                                                                                                                                                                                                                                                }

                                                                                                                                                                                                                                                }

                                                                                                                                                                                                                                                cleardevice();

                                                                                                                                                                                                                                                for(i=0;i<n;i++)

                                                                                                                                                                                                                                                                line(320+c[i][0],240-c[i][1],320+c[i+1][0],240-c[i+1][1]);

                                                                                                                                                                                                                                                                line(0,240,639,240);

                                                                                                                                                                                                                                                                line(320,0,320,479);

                                                                                                                                                                                                                                                                getch();

                                                                                                                                                                                                                                                                break;

                                                                                                                                                                                                                                                                default:

                                                                                                                                                                                                                                                                break;

                                                                                                                                                                } break;

                                                                                                                case 7: exit(1);

                                                                                                                                                                                                                closegraph();

                                                                                                                                                                                                                restorecrtmode();

                                                                                                                                                                                                                break;

                                                                                                                                                                                                                default: break;

                                }

                                                                                                                                                                                                               

                }

}





























--
Hackerx Sasi
Don't ever give up.
Even when it seems impossible,
Something will always
pull you through.
The hardest times get even
worse when you lose hope.
As long as you believe you can do it, You can.

But When you give up,
You lose !
I DONT GIVE UP.....!!!

with regards
prem sasi kumar arivukalanjiam




--
Hackerx Sasi
Don't ever give up.
Even when it seems impossible,
Something will always
pull you through.
The hardest times get even
worse when you lose hope.
As long as you believe you can do it, You can.

But When you give up,
You lose !
I DONT GIVE UP.....!!!

with regards
prem sasi kumar arivukalanjiam

No comments:

Post a Comment

Slider

Image Slider By engineerportal.blogspot.in The slide is a linking image  Welcome to Engineer Portal... #htmlcaption

Tamil Short Film Laptaap

Tamil Short Film Laptaap
Laptapp

Labels

About Blogging (1) Advance Data Structure (2) ADVANCED COMPUTER ARCHITECTURE (4) Advanced Database (4) ADVANCED DATABASE TECHNOLOGY (4) ADVANCED JAVA PROGRAMMING (1) ADVANCED OPERATING SYSTEMS (3) ADVANCED OPERATING SYSTEMS LAB (2) Agriculture and Technology (1) Analag and Digital Communication (1) Android (1) Applet (1) ARTIFICIAL INTELLIGENCE (3) aspiration 2020 (3) assignment cse (12) AT (1) AT - key (1) Attacker World (6) Basic Electrical Engineering (1) C (1) C Aptitude (20) C Program (87) C# AND .NET FRAMEWORK (11) C++ (1) Calculator (1) Chemistry (1) Cloud Computing Lab (1) Compiler Design (8) Computer Graphics Lab (31) COMPUTER GRAPHICS LABORATORY (1) COMPUTER GRAPHICS Theory (1) COMPUTER NETWORKS (3) computer organisation and architecture (1) Course Plan (2) Cricket (1) cryptography and network security (3) CS 810 (2) cse syllabus (29) Cyberoam (1) Data Mining Techniques (5) Data structures (3) DATA WAREHOUSING AND DATA MINING (4) DATABASE MANAGEMENT SYSTEMS (8) DBMS Lab (11) Design and Analysis Algorithm CS 41 (1) Design and Management of Computer Networks (2) Development in Transportation (1) Digital Principles and System Design (1) Digital Signal Processing (15) DISCRETE MATHEMATICS (1) dos box (1) Download (1) ebooks (11) electronic circuits and electron devices (1) Embedded Software Development (4) Embedded systems lab (4) Embedded systems theory (1) Engineer Portal (1) ENGINEERING ECONOMICS AND FINANCIAL ACCOUNTING (5) ENGINEERING PHYSICS (1) english lab (7) Entertainment (1) Facebook (2) fact (31) FUNDAMENTALS OF COMPUTING AND PROGRAMMING (3) Gate (3) General (3) gitlab (1) Global warming (1) GRAPH THEORY (1) Grid Computing (11) hacking (4) HIGH SPEED NETWORKS (1) Horizon (1) III year (1) INFORMATION SECURITY (1) Installation (1) INTELLECTUAL PROPERTY RIGHTS (IPR) (1) Internal Test (13) internet programming lab (20) IPL (1) Java (38) java lab (1) Java Programs (28) jdbc (1) jsp (1) KNOWLEDGE MANAGEMENT (1) lab syllabus (4) MATHEMATICS (3) Mechanical Engineering (1) Microprocessor and Microcontroller (1) Microprocessor and Microcontroller lab (11) migration (1) Mini Projects (1) MOBILE AND PERVASIVE COMPUTING (15) MOBILE COMPUTING (1) Multicore Architecute (1) MULTICORE PROGRAMMING (2) Multiprocessor Programming (2) NANOTECHNOLOGY (1) NATURAL LANGUAGE PROCESSING (1) NETWORK PROGRAMMING AND MANAGEMENT (1) NETWORKPROGNMGMNT (1) networks lab (16) News (14) Nova (1) NUMERICAL METHODS (2) Object Oriented Programming (1) ooad lab (6) ooad theory (9) OPEN SOURCE LAB (22) openGL (10) Openstack (1) Operating System CS45 (2) operating systems lab (20) other (4) parallel computing (1) parallel processing (1) PARALLEL PROGRAMMING (1) Parallel Programming Paradigms (4) Perl (1) Placement (3) Placement - Interview Questions (64) PRINCIPLES OF COMMUNICATION (1) PROBABILITY AND QUEUING THEORY (3) PROGRAMMING PARADIGMS (1) Python (3) Question Bank (1) question of the day (8) Question Paper (13) Question Paper and Answer Key (3) Railway Airport and Harbor (1) REAL TIME SYSTEMS (1) RESOURCE MANAGEMENT TECHNIQUES (1) results (3) semester 4 (5) semester 5 (1) Semester 6 (5) SERVICE ORIENTED ARCHITECTURE (1) Skill Test (1) software (1) Software Engineering (4) SOFTWARE TESTING (1) Structural Analysis (1) syllabus (34) SYSTEM SOFTWARE (1) system software lab (2) SYSTEMS MODELING AND SIMULATION (1) Tansat (2) Tansat 2011 (1) Tansat 2013 (1) TCP/IP DESIGN AND IMPLEMENTATION (1) TECHNICAL ENGLISH (7) Technology and National Security (1) Theory of Computation (3) Thought for the Day (1) Timetable (4) tips (4) Topic Notes (7) tot (1) TOTAL QUALITY MANAGEMENT (4) tutorial (8) Ubuntu LTS 12.04 (1) Unit Wise Notes (1) University Question Paper (1) UNIX INTERNALS (1) UNIX Lab (21) USER INTERFACE DESIGN (3) VIDEO TUTORIALS (1) Virtual Instrumentation Lab (1) Visual Programming (2) Web Technology (11) WIRELESS NETWORKS (1)

LinkWithin