Algorithm:
/* Reflection Programe*/
/* Source Code Written By Vishal Nagda, Using IDE DEV-C++ 4.9.9.2 */
Reflection About The Line Y = 0 OR Reflection Of An Object The X Axis Rf[3][3] = { {1, 0, 0}, {0, -1, 0}, {0, 0, 1} }; Reflection About The Line X = 0 OR Reflection Of An Object The Y Axis Rf[3][3] = { {-1, 0, 0}, {0, 1, 0}, {0, 0, 1} }; Reflection Of An Object About The X & Y Axis Rf[3][3] = { {-1, 0, 0}, {0, -1, 0}, {0, 0, 1} }; Reflection Of An Object With Respect TO The Line Y = X Axis Rf[3][3] = { {0, 1, 0}, {1, 0, 0}, {0, 0, 1} }; Reflection Of An Object With Respect TO The Line Y = -X Axis Rf[3][3] = { {0, -1, 0}, {-1, 0, 0}, {0, 0, 1} };
Program:
#include<graphics.h> int main() { int x=400,y=250,x1=450,y1=360,x2=280,y2=360,sx =2,sy=2,i,j,k; int cx=(x+x1+x2)/3,cy=(y+y1+y2)/3; int ref[3][3]={{-1, 0, 0}, {0, -1, 0}, {0, 0, 1}}, trans[3][3]={{1,0,cx},{0,1,cy},{0,0,1}}, trans1[3][3]={{1,0,-cx},{0,1,-cy},{0,0,1}}, tri[3][3]={{x,x1,x2},{y,y1,y2},{1,1,1}},ans[3][3],orig[3][3]; initwindow(800,600,"reflection"); outtextxy(80,60,"reflection"); outtextxy(80,500,"Please Press Enter Key"); line(tri[0][0],tri[1][0],tri[0][1],tri[1][1]); line(tri[0][1],tri[1][1],tri[0][2],tri[1][2]); line(tri[0][2],tri[1][2],tri[0][0],tri[1][0]); getch(); for(i=0;i<3;i++) for(j=0;j<3;j++) { ans[i][j]=0; for(k=0;k<3;k++) ans[i][j]+=trans[i][k]*ref[k][j]; } for(i=0;i<3;i++) for(j=0;j<3;j++) { orig[i][j]=0; for(k=0;k<3;k++) orig[i][j]+=ans[i][k]*trans1[k][j]; } for(i=0;i<3;i++) for(j=0;j<3;j++) { ans[i][j]=0; for(k=0;k<3;k++) ans[i][j]+=orig[i][k]*tri[k][j]; } cleardevice(); outtextxy(80,60,"reflection"); line(ans[0][0],ans[1][0],ans[0][1],ans[1][1]); line(ans[0][1],ans[1][1],ans[0][2],ans[1][2]); line(ans[0][2],ans[1][2],ans[0][0],ans[1][0]); getch(); while(!kbhit()); return 0; }