Write a program to use of 2D Reflection technique.....
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
struct s
{
int x,y ;
};
void main()
{
int n;
int gd= DETECT ,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
int xmax,ymax;
xmax=getmaxx();
ymax=getmaxy();
// cout<<xmax<<" "<<ymax;
line(0,240,639,240);
line(320,0,320,479);
struct s inp[10],out[10];
printf("\n Wellcome Back .........TM");
printf ("\n enter the no of vertices");
scanf ("%d",&n);
for(int i=0;i<n;i++)
{
scanf ("%d%d",&inp[i].x,&inp[i].y);
}
for(i=0;i<n;i++)
{
inp[i].x=inp[i].x+320;
}
printf("\n enter your choice for reflection along different axes");
printf("\n 1 along x - axis");
printf("\n 2 along y axis");
printf("\n 3 along x=y axis");
printf("\n 4 along x= -y axis");
printf("\n 5 along origin");
int ch;
scanf ("%d",&ch);
switch(ch)
{
case 1:
for(i=0;i<n;i++)
{
out[i].x=inp[i].x;
out[i].y=(240-(inp[i].y))+240;
}
break;
case 2:
for( i=0;i<n;i++)
{
out[i].x= 320-(inp[i].x-320);
out[i].y= inp[i].y;
}
break;
default :
printf("\n wrong choice");
}
inp[n]= inp[0];
out[n] = out[0];
for(i=0;i<n;i++)
{
setcolor(5);
line(inp[i].x,inp[i].y,inp[i+1].x,inp[i+1].y);
}
for(i=0;i<n;i++)
{
setcolor(5);
line(out[i].x,out[i].y,out[i+1].x,out[i+1].y);
}
getch();
for(i=0;i<n;i++)
{
printf("%d%d",out[i].x,out[i].y);
}
getch();
for(i=0;i<n;i++)
{
setcolor(5);
line(out[i].x,out[i].y,out[i+1].x,out[i+1].y);
}
getch();
closegraph();
}
Output:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
struct s
{
int x,y ;
};
void main()
{
int n;
int gd= DETECT ,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
int xmax,ymax;
xmax=getmaxx();
ymax=getmaxy();
// cout<<xmax<<" "<<ymax;
line(0,240,639,240);
line(320,0,320,479);
struct s inp[10],out[10];
printf("\n Wellcome Back .........TM");
printf ("\n enter the no of vertices");
scanf ("%d",&n);
for(int i=0;i<n;i++)
{
scanf ("%d%d",&inp[i].x,&inp[i].y);
}
for(i=0;i<n;i++)
{
inp[i].x=inp[i].x+320;
}
printf("\n enter your choice for reflection along different axes");
printf("\n 1 along x - axis");
printf("\n 2 along y axis");
printf("\n 3 along x=y axis");
printf("\n 4 along x= -y axis");
printf("\n 5 along origin");
int ch;
scanf ("%d",&ch);
switch(ch)
{
case 1:
for(i=0;i<n;i++)
{
out[i].x=inp[i].x;
out[i].y=(240-(inp[i].y))+240;
}
break;
case 2:
for( i=0;i<n;i++)
{
out[i].x= 320-(inp[i].x-320);
out[i].y= inp[i].y;
}
break;
default :
printf("\n wrong choice");
}
inp[n]= inp[0];
out[n] = out[0];
for(i=0;i<n;i++)
{
setcolor(5);
line(inp[i].x,inp[i].y,inp[i+1].x,inp[i+1].y);
}
for(i=0;i<n;i++)
{
setcolor(5);
line(out[i].x,out[i].y,out[i+1].x,out[i+1].y);
}
getch();
for(i=0;i<n;i++)
{
printf("%d%d",out[i].x,out[i].y);
}
getch();
for(i=0;i<n;i++)
{
setcolor(5);
line(out[i].x,out[i].y,out[i+1].x,out[i+1].y);
}
getch();
closegraph();
}
Output:


No comments:
Post a Comment