Advertisement
MHSS

Translation

May 1st, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<graphics.h>
  4. int i,x,y,tx,ty,sx,sy,angle=10,xmax,ymax,xmid,ymid,op=1;
  5. float p1[10]={50,50,100,50,100,100,50,100,50,50};
  6. float b[3][3]={1,0,0,0,1,0,0,0,1};
  7. int c[1][1];
  8. float a[1][1];
  9.  
  10. void trans(){
  11.     printf("\nEnter x translation: ");
  12.     scanf("%d",&tx);
  13.     printf("\nEnter y translation: ");
  14.     scanf("%d",&ty);
  15.     b[0][0]=1;b[0][1]=0;b[0][2]=0;b[1][0]=0;
  16.     b[1][1]=1;b[1][2]=0;b[2][0]=tx;b[2][1]=ty;b[2][2]=1;
  17. }
  18. void main(){
  19.     int gd=DETECT,gm;
  20.     clrscr();
  21.     initgraph(&gd, &gm, "C:\\tc\\bgi");
  22.     trans();
  23.     xmax=getmaxx();
  24.     ymax=getmaxy();
  25.     xmid=xmax/2;
  26.     ymid=ymax/2;
  27.     setcolor(1);
  28.     line(xmid,0,xmid,ymax);
  29.     line(0,ymid,xmax,ymid);
  30.     setcolor(4);
  31.     for(i=0;i<8;i=i+2)
  32.     line(p1[i]+xmid,ymid-p1[i+1],xmid+p1[i+2],ymid-p1[i+3]);
  33.     for(i=0;i<9;i=i+2){
  34.         a[0][0]=p1[i];a[0][1]=p1[i+1];
  35.         c[0][0]=a[0][0]*b[0][0]+a[0][1]*b[1][0]+b[2][0];
  36.         c[0][1]=a[0][0]*b[0][1]+a[0][1]*b[1][1]+b[2][1];
  37.         p1[i]=c[0][0];
  38.         p1[i+1]=c[0][1];
  39.     }
  40.     setcolor(15);
  41.     for(i=0;i<8;i=i+2)
  42.     line(p1[i]+xmid,ymid-p1[i+1],xmid+p1[i+2],ymid-p1[i+3]);
  43.     getch();
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement