2D REFLECTION


2D REFLECTION
AIM:
                      To write a program to implement 2D transformation as reflection
          ALGORITHM:

·         Declare the header file

·         Declare the variables and values

·         Using the graphics function create an image to implement the 2D reflection

·         Print the output of 2D image reflection

·         Stop the program
                       



CODINGS:

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int a,a1,b,b1,c,c1,xt,ch;
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
a=getmaxx();
a1=getmaxy();
b=a/2;
b1=a1/2;

line(b,0,b,a1);
line(0,b1,a,b1);
line(400,200,600,200);
line(400,200,400,100);
line(400,100,600,200);

printf("1.origin\n");
printf("2.x-axis\n");
printf("3.y-axis\n");
printf("4.exit\n");

do
{
printf("Enter your choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
      c=400-b;c1=200-b1;
      line(b-c,b1-c1,b-c-200,b1-c1);
      line(b-c,b1-c1,b-c,b1-c1+100);
      line(b-c,b1-c1+100,b-c-200,b1-c1);
      break;
case 2:
      c=400-b;c1=200-b1;
      line(b+c,b1-c1,b+c+200,b1-c1);
      line(b+c,b1-c1,b+c,b1-c1+100);
      line(b+c,b1-c1+100,b+c+200,b1-c1);
      break;


case 3:
      c=400-b;c1=200-b1;
      line(b-c,b1+c1,b-c-200,b1+c1);
      line(b-c,b1+c1,b-c,b1+c1-100);
      line(b-c,b1+c1-100,b-c-200,b1+c1);
      break;
}         

}while(ch<4);
getch();
closegraph();
}



OUTPUT:

1.      origin
2.      x-axis
3.      y-axis
   
      Enter your choice:1

      Enter your choice:2
      Enter your choice:3









                                                                                                                                              









RESULT:
           
            Thus, the program has been successfully executed & output is verified.

Comments

Post a Comment