niemsh0007

CG

Jan 9th, 2023
1,270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.31 KB | None | 0 0
  1. //Rotation
  2. #include<stdio.h>
  3. #include<conio.h>
  4. #include<graphics.h>
  5. #include<math.h>
  6.  
  7. void main(){
  8.   int gd=DETECT, r, gm, d, x1, y1, x2, y2, xn1, yn1, xn2, yn2;
  9.     float ra, si, co;
  10.     initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
  11.  
  12.     printf("Enter the value of X1 and Y1: ");
  13.     scanf("%d %d", &x1, &y1);
  14.  
  15.     printf("Enter the value of X2 and Y2: ");
  16.     scanf("%d %d", &x2, &y2);
  17.  
  18.     line(x1, y1, x2, y2);
  19.  
  20.     printf("Enter the degree of rotation: ");
  21.     scanf("%d", &d);
  22.  
  23.     //Starting point would be same
  24.     xn1 = x1;
  25.     yn1 = y1;
  26.  
  27.     //Convert Degree into radian
  28.     r = x2-x1;
  29.     ra = 0.0175 * d;
  30.     si = sin(ra);
  31.     co = cos(ra);
  32.     //second point
  33.     xn2 = x1 + r*co + 1;
  34.     yn2 = y1 + r*si + 1;
  35.  
  36.     line(xn1, yn1, xn2, yn2);
  37.  
  38.     getch();
  39. closegraph();
  40.    
  41.  
  42.  
  43. }
  44. //translation
  45. //Transation
  46. #include<stdio.h>
  47. #include<conio.h>
  48. #include<graphics.h>
  49. #include<math.h>
  50. void main(){
  51.     int gd=DETECT,gm;
  52.     int x1,y1,x2,y2,tx,ty,x3,y3,x4,y4;
  53.     initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
  54.  
  55.     printf("Enter the starting point of line segment:");
  56.     scanf("%d %d",&x1,&y1);
  57.      printf("Enter the ending point of line segment:");      
  58.     scanf("%d %d",&x2,&y2);
  59.      printf("Enter translation distances tx,ty:\n");
  60.      scanf("%d%d",&tx,&ty);
  61.  
  62.      setcolor(5);
  63.       line(x1,y1,x2,y2);
  64.       outtextxy(x2+2,y2+2,"Original line");
  65.      x3=x1+tx;
  66.       y3=y1+ty;
  67.       x4=x2+tx;
  68.       y4=y2+ty;
  69.       setcolor(7);
  70.       line(x3,y3,x4,y4);
  71.     outtextxy(x4+2,y4+2,"Line after translation");
  72.  
  73.     getch();
  74. }
  75. //scalling
  76. #include<stdio.h>
  77. #include<conio.h>
  78. #include<graphics.h>
  79. #include<math.h>
  80. void main(){
  81.     int gd=DETECT,gm;
  82.      float x1,y1,x2,y2,sx,sy,x3,y3,x4,y4;
  83.       initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
  84.  
  85.      printf("Enter the starting point coordinates:");
  86.       scanf("%f %f",&x1,&y1);
  87.       printf("Enter the ending point coordinates:");
  88.       scanf("%f %f",&x2,&y2);
  89.       printf("Enter scaling factors sx,sy:\n");
  90.       scanf("%f%f",&sx,&sy);
  91.  
  92.      setcolor(5);
  93.      line(x1,y1,x2,y2);
  94.       outtextxy(x2+2,y2+2,"Original line");
  95.      x3=x1*sx;
  96.       y3=y1*sy;
  97.       x4=x2*sx;
  98.       y4=y2*sy;
  99.       setcolor(7);
  100.       line(x3,y3,x4,y4);
  101.       outtextxy(x4+2,y4+2,"Line after scaling");
  102.       getch();
  103. }
Advertisement
Add Comment
Please, Sign In to add comment