0% found this document useful (0 votes)
146 views4 pages

2D Reflection Shearing

The document contains a C program for performing two-dimensional transformations, specifically reflection and shearing. It includes a menu-driven interface allowing users to choose different types of reflections and shearing operations on a set of vertices. The program utilizes graphics functions to display the transformations visually.

Uploaded by

ansarikashifx7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
146 views4 pages

2D Reflection Shearing

The document contains a C program for performing two-dimensional transformations, specifically reflection and shearing. It includes a menu-driven interface allowing users to choose different types of reflections and shearing operations on a set of vertices. The program utilizes graphics functions to display the transformations visually.

Uploaded by

ansarikashifx7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PRACTICAL NO: 09

Q) Write a program in C for two dimensional transformation(Reflection and


shearing).

Code:
#include<stdio.h> printf("\n\t* * MENU * *"); printf("\
#include<process.h> n\t1) ABOUT X-AXIS"); printf("\n\t2)
#include<conio.h> ABOUT Y-AXIS"); printf("\n\t3)
#include<graphics.h> ABOUT ORIGIN"); printf("\n\t4)
#include<math.h> ABOUT X=Y"); printf("\n\t5) ABOUT -
void disp(int n,float c[][3]) X=Y"); printf("\n\t6) EXIT"); printf("n\
{ tENTER YOUR CHOICE :" );
float maxx,maxy; scanf("%d",&ch);
int i; clrscr();
maxx=getmaxx(); cleardevice();
maxy=getmaxy(); disp(n,c);
maxx=maxx/2; for(i=0;i<3;i++)
maxy=maxy/2; for(j=0;j<3;j++)
i=0; { b[i]
while(i<n-1) [j]=0;
{ if(i==j)
line(maxx+c[i][0],maxy-c[i][1],maxx+c[i+1][0],maxy- b[i][j]=1;
c[i+1][1]); }
i++; switch(ch)
} {
i=n-1; case 1:
line(maxx+c[i][0],maxy-c[i][1],maxx+c[0][0],maxy- b[1][1]=-1;
c[0][1]); break;
setcolor(GREEN); case 2:
line(0,maxy,maxx*2,maxy); b[0][0]=-1;
line(maxx,0,maxx,maxy*2); break;
setcolor(WHITE); case 3:
} b[0][0]=-1;
void mul(int n,float b[][3],float c[][3],float a[][3]) b[1][1]=-1;
{ break;
int i,j,k; case 4:
for(i=0;i<n;i++) b[0][0]=0;
for(j=0;j<3;j++) b[1][1]=0;
a[i][j]=0; b[0][1]=1;
for(i=0;i<n;i++) b[1][0]=1;
for(j=0;j<3;j++) break;
for(k=0;k<3;k++) case 5:
{ b[0][0]=0;
a[i][j] = a[i][j] + (c[i][k] * b[k][j]); b[1][1]=0;
} b[0][1]=-1;
} b[1][0]=-1;
void reflection(int n,float c[][3]) break;
{ case 6:
float b[10][3],a[10][3]; break;
int i=0,ch,j; default:
cleardevice();
PRACTICAL NO: 09
printf("\n\tINVALID CHOICE ! "); float c[10][3],tx,ty,sx,sy,ra;
break; initgraph(&gd,&gm, "C:\\TC\\BGI"); printf("\
} nEnter the number of vertices : ");
mul(n,b,c,a); scanf("%d",&n);
setcolor(RED); for(i=0;i<n;i++)
disp(n,a); {
} printf("\nEnter the co-ordinates of the %d vertex
void shearing(int n,float c[][3]) :",i+1);
{ scanf("%f%f",&c[i][0],&c[i][1]); c[i]
float b[10][3],sh,a[10] [2]=1;
[3]; int i=0,ch,j; }
cleardevice(); do
printf("\n\t* * * MENU * * *"); {
printf("\n\t1) X SHEARING"); printf("\ clrscr();
n\t2) Y SHEARING"); printf("\n\t3) cleardevice();
EXIT "); printf("\n\tENTER YOUR printf("\n\t\t\t * * * MENU * * *");
CHOICE : "); scanf("%d",&ch); printf("\n\t 1) REFLECTION ");
if(ch==3 printf("\n\t 2) SHEARING");
) return; printf("\n\t 3) EXIT")
printf("\n\tENTER THE VALUE for SHEARING: printf("\n\t ENTER YOUR CHOICE: ");
") scanf("%d",&cho);
; scanf("%f",&sh); switch(cho)
clrscr(); {
cleardevice(); case 1:
for(i=0;i<3;i++) clrscr();
for(j=0;j<3;j++) cleardevice();
b[i][j]=0; setcolor(BLUE);
for(i=0;i<3;i++) disp(n,c);
b[i][i]=1; reflection(n,c);
switch(ch) getch();
{ break;
case 1: case
b[1][0]=sh; 2:
break; clrscr();
case cleardevice();
2: setcolor(BLUE);
b[0][1]=sh; disp(n,c);
break; shearing(n,c);
case getch();
3: break;
break; case 3
default :
: exit(0);
printf("\n\tINVALID CHOICE ! "); break;
break; default
} :
mul(n,b,c,a); printf("\n\tInvalid choice !!");
setcolor(RED); break;
disp(n,a); }
} }while(cho!=3);
void main() getch();
{ closegraph();
int i,j,k,cho,n,gd=DETECT,gm; }
PRACTICAL NO: 09
Output:
Reflection about y-axis:

Reflection about origin


Reflection about x-axis:

Reflection about x=y


PRACTICAL NO: 09
Y-shearing

Reflection about –x=y

X shearing

You might also like