Reflection And Shearing In Computer Graphics Program

broken image
Reflection And Shearing In Computer Graphics Program
Reflection and shearing in computer graphics program

This program is for the reflection and sharing of triangle. Here the lower first quadrant triangle is reflected to upper first quadrant, the resultant triangle is again reflected to upper second quadrant similarly the process is continue. In case of sharing two option are shown sharing on x-axis and y-axis. About Press Copyright Contact us Creators Advertise Developers Terms Privacy Policy & Safety How YouTube works Test new features Press Copyright Contact us Creators. Computer Graphics – 3D Shearing Transformation. Shearing transformation is the same as we see in 2D space, but here we have to deal with the x, y, and z axes whereas in 2D we deal with the only x and y axes. Shearing is the process of slanting an object in 3D space either in x, y, or in the z-direction. Shearing changes (or deformed) the. If user choose reflection then rotate the triangle in 1800 at (x2, y2) and draw the rotated triangle (which is reflected triangle). If user choose shearing then get the shear value and draw the sheared triangle in the following coordinates (x1, y1, x2+x, y2, x3, y3).

Program

Reflection And Shearing In Computer Graphics Program Using

Shearing

#include
#include
#include
#include
using namespace std;
voiddisp(intn,float c[][3]){
floatmaxx,maxy;
inti;
maxx=getmaxx();
maxy=getmaxy();
maxx=maxx/2;
maxy=maxy/2;
i=0;
while(iline(maxx+c[i][0],maxy-c[i][1],maxx+c[i+1][0],maxy-c[i+1][1]);
i++; }
i=n-1;
line(maxx+c[i][0],maxy-c[i][1],maxx+c[0][0],maxy-c[0][1]);
setcolor(GREEN);
line(0,maxy,maxx*2,maxy);
line(maxx,0,maxx,maxy*2);
setcolor(WHITE);}
void mul(intn,float b[][3],float c[][3],float a[][3]){
inti,j,k;
for(i=0;ifor(j=0;j<3;j++)
a[i][j]=0;
for(i=0;ifor(j=0;j<3;j++)
for(k=0;k<3;k++) {
a[i][j]=a[i][j]+(c[i][k]*b[k][j]); }}
void translation(intn,float c[][3],float tx,floatty){
inti;
for(i=0;ic[i][0]=c[i][0]+tx;
c[i][1]=c[i][1]+ty; }}
void scaling(intn,float c[][3],float sx,floatsy){
float b[10][3],a[10][3];
inti,j;
for(j=0;j<3;j++)
b[i][j]=0;
b[0][0]=sx;
b[1][1]=sy;
b[2][2]=1;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
void rotation(intn,float c[][3],float ra){
inti=0,j;
float b[10][3],xp,yp,a[10][3];
xp=c[0][0];
yp=c[0][1];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[0][0]=b[1][1]=cos(ra*3.14/180);
b[0][1]=sin(ra*3.14/180);
b[1][0]=-sin(ra*3.14/180);;
b[2][0]=(-xp*cos(ra*3.14/180))+(yp*sin(ra*3.14/180))+xp;
b[2][1]=(-xp*sin(ra*3.14/180))-(yp*cos(ra*3.14/180))+yp;
b[2][2]=1;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
voidrefthx(intn,float c[][3]){
inti=0,j;
float b[10][3],a[10][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[0][0]=b[2][2]=1;
b[1][1]=-1;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
voidrefthy(intn,float c[][3]){
inti=0,j;
float b[10][3],a[10][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[1][1]=b[2][2]=1;
b[0][0]=-1;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
voidreforg(intn,float c[][3]){
inti=0,j;
float b[10][3],a[10][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[0][0]=b[1][1]=-1;
b[2][2]=1;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
voidrefthyx(intn,float c[][3]){
inti=0,j;
float b[10][3],a[10][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[0][1]=b[1][0]=b[2][2]=1;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
voidrefthynegx(intn,float c[][3]){
inti=0,j;
float b[10][3],a[10][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[0][1]=b[1][0]=-1;
b[2][2]=1;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
voidshearx(intn,float c[][3],float shx){
inti=0,j;
float b[10][3],a[10][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[0][0]=b[1][1]=b[2][2]=1;
b[1][0]=shx;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
voidsheary(intn,float c[][3],float shy){
inti=0,j;
float b[10][3],a[10][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[0][0]=b[1][1]=b[2][2]=1;
b[0][1]=shy;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
int main(){
inti,j,k,cho,n,gd=DETECT,gm;
float c[10][3],tx,ty,sx,sy,ra;
initgraph(&gd,&gm,' ');
cout<<'Enter no. of vertices';
cin>>n;
for (i=0;icout<<'Enter coordinates of vertex',i+1;
cin>>c[i][0]>>c[i][1];
c[i][2]=1; }
do {
cleardevice();
cout<<'ntt ——MENU——';
cout<<'ntt 1)Translation';
cout<<'ntt 2)Scaling';
cout<<'ntt 3)Rotation';
cout<<'ntt 4)Reflection';
cout<<'ntt 5)Shear';
cout<<'ntt 6)EXIT';
cout<<'nt Enter your Choice';
cin>>cho;
switch(cho) {
case 1:
cout<<'nt Enter translation factor for X and Y axis:t';
cin>>tx>>ty;
cleardevice();
setcolor(15);
disp(n,c);
translation(n,c,tx,ty);
setcolor(15);
disp(n,c);
getch();
break;
case 2:
cout<<'nt Enter scaling factor for X and Y axis:t';
cin>>sx>>sy;
cleardevice();
setcolor(15);
disp(n,c);
scaling(n,c,sx,sy);
getch();
break;
case 3:
cout<<'nt Enter rotation factor :t';
cin>>ra;
cleardevice();
disp(n,c);
rotation(n,c,ra);
getch();
break;
case 4:
intch;
do{
cleardevice();
cout<<'ntt ——MENU——';
cout<<'ntt 1)Reflection about x axis';
cout<<'ntt 2)Reflection about x axis';
cout<<'ntt 3)Reflection about origin';
cout<<'ntt 4)Reflection about the line y=x';
cout<<'ntt 4)Reflection about the line y=-x';
cout<<'nt Enter your Choice';
cin>>ch;
switch(ch){
case 1:
cleardevice();
setcolor(15);
disp(n,c);
refthx(n,c);
getch();
break;
case 2:
cleardevice();
setcolor(15);
disp(n,c);
refthy(n,c);
getch();
break;
case 3:
cleardevice();
setcolor(15);
disp(n,c);
reforg(n,c);
getch();
break;
case 4:
cleardevice();
setcolor(15);
disp(n,c);
refthyx(n,c);
getch();
break;
case 5:
cleardevice();
setcolor(15);
disp(n,c);
refthynegx(n,c);
getch();
break;
default:
cout<<'nt Invalid Choice !!!';
break; } }
while(cho!=5);
case 5:
int cha;
floatshx,shy;
do {
cleardevice();
cout<<'ntt ——MENU——';
cout<<'ntt 1)X-shear';
cout<<'ntt 2)Y-shear';
cout<<'nt Enter your Choice';
cin>>cha;
switch(cha) {
case 1:
cout<<'nt Enter Shear factor: ';
cin>>shx;
cleardevice();
setcolor(15);
disp(n,c);
shearx(n,c,shx);
getch();
break;
case 2:
cout<<'nt Enter Shear factor: ';
cin>>shy;
cleardevice();
setcolor(15);
disp(n,c);
shearx(n,c,shy);
getch();
break;
default:
cout<<'nt Invalid Choice !!!';
break; } }
while(cho!=2);
case 6:
exit(0);
break;
default:
cout<<'nt Invalid Choice !!!';
break; } }
while(cho!=6);
getch();
closegraph();}

Reflection And Shearing In Computer Graphics Program Free

Graphics

This program is for the reflection and sharing of triangle. Here the lower first quadrant triangle is reflected to upper first quadrant, the resultant triangle is again reflected to upper second quadrant similarly the process is continue. In case of sharing two option are shown sharing on x-axis and y-axis. About Press Copyright Contact us Creators Advertise Developers Terms Privacy Policy & Safety How YouTube works Test new features Press Copyright Contact us Creators. Computer Graphics – 3D Shearing Transformation. Shearing transformation is the same as we see in 2D space, but here we have to deal with the x, y, and z axes whereas in 2D we deal with the only x and y axes. Shearing is the process of slanting an object in 3D space either in x, y, or in the z-direction. Shearing changes (or deformed) the. If user choose reflection then rotate the triangle in 1800 at (x2, y2) and draw the rotated triangle (which is reflected triangle). If user choose shearing then get the shear value and draw the sheared triangle in the following coordinates (x1, y1, x2+x, y2, x3, y3).

Reflection And Shearing In Computer Graphics Program Using

#include
#include
#include
#include
using namespace std;
voiddisp(intn,float c[][3]){
floatmaxx,maxy;
inti;
maxx=getmaxx();
maxy=getmaxy();
maxx=maxx/2;
maxy=maxy/2;
i=0;
while(iline(maxx+c[i][0],maxy-c[i][1],maxx+c[i+1][0],maxy-c[i+1][1]);
i++; }
i=n-1;
line(maxx+c[i][0],maxy-c[i][1],maxx+c[0][0],maxy-c[0][1]);
setcolor(GREEN);
line(0,maxy,maxx*2,maxy);
line(maxx,0,maxx,maxy*2);
setcolor(WHITE);}
void mul(intn,float b[][3],float c[][3],float a[][3]){
inti,j,k;
for(i=0;ifor(j=0;j<3;j++)
a[i][j]=0;
for(i=0;ifor(j=0;j<3;j++)
for(k=0;k<3;k++) {
a[i][j]=a[i][j]+(c[i][k]*b[k][j]); }}
void translation(intn,float c[][3],float tx,floatty){
inti;
for(i=0;ic[i][0]=c[i][0]+tx;
c[i][1]=c[i][1]+ty; }}
void scaling(intn,float c[][3],float sx,floatsy){
float b[10][3],a[10][3];
inti,j;
for(j=0;j<3;j++)
b[i][j]=0;
b[0][0]=sx;
b[1][1]=sy;
b[2][2]=1;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
void rotation(intn,float c[][3],float ra){
inti=0,j;
float b[10][3],xp,yp,a[10][3];
xp=c[0][0];
yp=c[0][1];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[0][0]=b[1][1]=cos(ra*3.14/180);
b[0][1]=sin(ra*3.14/180);
b[1][0]=-sin(ra*3.14/180);;
b[2][0]=(-xp*cos(ra*3.14/180))+(yp*sin(ra*3.14/180))+xp;
b[2][1]=(-xp*sin(ra*3.14/180))-(yp*cos(ra*3.14/180))+yp;
b[2][2]=1;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
voidrefthx(intn,float c[][3]){
inti=0,j;
float b[10][3],a[10][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[0][0]=b[2][2]=1;
b[1][1]=-1;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
voidrefthy(intn,float c[][3]){
inti=0,j;
float b[10][3],a[10][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[1][1]=b[2][2]=1;
b[0][0]=-1;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
voidreforg(intn,float c[][3]){
inti=0,j;
float b[10][3],a[10][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[0][0]=b[1][1]=-1;
b[2][2]=1;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
voidrefthyx(intn,float c[][3]){
inti=0,j;
float b[10][3],a[10][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[0][1]=b[1][0]=b[2][2]=1;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
voidrefthynegx(intn,float c[][3]){
inti=0,j;
float b[10][3],a[10][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[0][1]=b[1][0]=-1;
b[2][2]=1;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
voidshearx(intn,float c[][3],float shx){
inti=0,j;
float b[10][3],a[10][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[0][0]=b[1][1]=b[2][2]=1;
b[1][0]=shx;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
voidsheary(intn,float c[][3],float shy){
inti=0,j;
float b[10][3],a[10][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[0][0]=b[1][1]=b[2][2]=1;
b[0][1]=shy;
mul(n,b,c,a);
setcolor(RED);
disp(n,a);}
int main(){
inti,j,k,cho,n,gd=DETECT,gm;
float c[10][3],tx,ty,sx,sy,ra;
initgraph(&gd,&gm,' ');
cout<<'Enter no. of vertices';
cin>>n;
for (i=0;icout<<'Enter coordinates of vertex',i+1;
cin>>c[i][0]>>c[i][1];
c[i][2]=1; }
do {
cleardevice();
cout<<'ntt ——MENU——';
cout<<'ntt 1)Translation';
cout<<'ntt 2)Scaling';
cout<<'ntt 3)Rotation';
cout<<'ntt 4)Reflection';
cout<<'ntt 5)Shear';
cout<<'ntt 6)EXIT';
cout<<'nt Enter your Choice';
cin>>cho;
switch(cho) {
case 1:
cout<<'nt Enter translation factor for X and Y axis:t';
cin>>tx>>ty;
cleardevice();
setcolor(15);
disp(n,c);
translation(n,c,tx,ty);
setcolor(15);
disp(n,c);
getch();
break;
case 2:
cout<<'nt Enter scaling factor for X and Y axis:t';
cin>>sx>>sy;
cleardevice();
setcolor(15);
disp(n,c);
scaling(n,c,sx,sy);
getch();
break;
case 3:
cout<<'nt Enter rotation factor :t';
cin>>ra;
cleardevice();
disp(n,c);
rotation(n,c,ra);
getch();
break;
case 4:
intch;
do{
cleardevice();
cout<<'ntt ——MENU——';
cout<<'ntt 1)Reflection about x axis';
cout<<'ntt 2)Reflection about x axis';
cout<<'ntt 3)Reflection about origin';
cout<<'ntt 4)Reflection about the line y=x';
cout<<'ntt 4)Reflection about the line y=-x';
cout<<'nt Enter your Choice';
cin>>ch;
switch(ch){
case 1:
cleardevice();
setcolor(15);
disp(n,c);
refthx(n,c);
getch();
break;
case 2:
cleardevice();
setcolor(15);
disp(n,c);
refthy(n,c);
getch();
break;
case 3:
cleardevice();
setcolor(15);
disp(n,c);
reforg(n,c);
getch();
break;
case 4:
cleardevice();
setcolor(15);
disp(n,c);
refthyx(n,c);
getch();
break;
case 5:
cleardevice();
setcolor(15);
disp(n,c);
refthynegx(n,c);
getch();
break;
default:
cout<<'nt Invalid Choice !!!';
break; } }
while(cho!=5);
case 5:
int cha;
floatshx,shy;
do {
cleardevice();
cout<<'ntt ——MENU——';
cout<<'ntt 1)X-shear';
cout<<'ntt 2)Y-shear';
cout<<'nt Enter your Choice';
cin>>cha;
switch(cha) {
case 1:
cout<<'nt Enter Shear factor: ';
cin>>shx;
cleardevice();
setcolor(15);
disp(n,c);
shearx(n,c,shx);
getch();
break;
case 2:
cout<<'nt Enter Shear factor: ';
cin>>shy;
cleardevice();
setcolor(15);
disp(n,c);
shearx(n,c,shy);
getch();
break;
default:
cout<<'nt Invalid Choice !!!';
break; } }
while(cho!=2);
case 6:
exit(0);
break;
default:
cout<<'nt Invalid Choice !!!';
break; } }
while(cho!=6);
getch();
closegraph();}

Reflection And Shearing In Computer Graphics Program Free

Reflection And Shearing In Computer Graphics Programming

/* C PROGRAM TO DEMONSTRATE SHEARING TRANSFORMATION*/

/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/
#include
#include
#include
#include
void main()
{
int poly[30],a[9][3],b[3][3],c[9][3],poly2[30];
int x=0,y=0,p,i,j,k,xc,yc,ch;
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,'C:/TC/BGI');
xc=getmaxx()/2;
yc=getmaxy()/2;

setcolor(1);
setbkcolor(15);
setfillstyle(6,3);

printf('n Enter number of points : ');
scanf('%d',&p);
j=0;
for(i=0;i{
printf('n Enter cordinate point x%d and y%d : ',j+1,j+1);

scanf('%d',&poly[i]);
scanf('%d',&poly[i+1]);
j++;
}
poly[p*2]=poly[0];
poly[p*2+1]=poly[1];

for(i=0;i{
poly2[i]=xc+poly[i];
poly2[i+1]=yc-poly[i+1];

}
poly2[p*2]=poly2[0];
poly2[p*2+1]=poly2[1];

fillpoly(p+1,poly2);
line(0,yc,xc*2,yc);
line(xc,0,xc,yc*2);

printf('n Shearing of : n 1. x n 2. y n 3. Bothn enter choice : ');
scanf('%d',&ch);
if(ch1)
{
printf('n Enter x shear value : ');
scanf('%d',&x);
}
if(ch2)
{
printf('n Enter y shear value : ');
scanf('%d',&y);
}
if(ch3)
{
printf('n Enter x shear value : ');
scanf('%d',&x);
printf('n Enter y shear value : ');
scanf('%d',&y);
}

j=0;
for(i=0;i{
a[i][0]=poly[j];
a[i][1]=poly[++j];
a[i][2]=1;
++j;
}

if(ch1)
{
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j]=0;
if(ij)
{
b[i][j]=1;
}
}
}
b[1][0]=x;

}
else if(ch2)
{
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j]=0;
if(ij)
{
b[i][j]=1;
}
}
}
b[0][1]=y;

}
else if(ch3)
{
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j]=0;
if(ij)
{
b[i][j]=1;
}
}
}

b[1][0]=x;
b[0][1]=y;

}
for(i=0;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];
}
}

}
printf('nnnnnt After Shearing : ');

for(i=0,j=0;i{
poly[j] =xc+c[i][0];
poly[j+1]=yc-c[i][1];
}
poly[j] =poly[0];
poly[j+1]=poly[1];

setfillstyle(9,2);
fillpoly(p+1,poly);

getch();
closegraph();
}





broken image