Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views3 pages

Include Include Include Using Namespace

The document contains a C++ program that performs geometric transformations such as translation, rotation, and scaling on a set of points. Users can select the type of transformation and input the necessary parameters, which are then applied to the points using matrix multiplication. The program utilizes graphics functions to display the original and transformed shapes on the screen.

Uploaded by

programbeastt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Include Include Include Using Namespace

The document contains a C++ program that performs geometric transformations such as translation, rotation, and scaling on a set of points. Users can select the type of transformation and input the necessary parameters, which are then applied to the points using matrix multiplication. The program utilizes graphics functions to display the original and transformed shapes on the screen.

Uploaded by

programbeastt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

10/23/24, 6:19 AM Convert Code to PDF Online: Free Tool for Programming Languages

1
2 #include<iostream>
3 #include<graphics.h>
4 #include<math.h>
5 using namespace std;
6
7 int pi[10]; //total points i.e x & y
8 double b[3][3]={1,0,0,0,1,0,0,0,1};
9 int c[1][1];
10 float a[1][1];
11
12 void matmul(float[]);
13
14 int main()
15 {
16 int i,x,y,tx,ty,sx,sy,angle=10,xmax,ymax,xmid,ymid,op;
17 int gm,gd=DETECT;
18 float p1[10]={50,50,
19 100,50,
20 100,100,
21 50,100,
22 50,50};
23
24 cout<<"\nSelect transformation:";
25 cout<<"\n1.Translation";
26 cout<<"\n2.Rotation:";
27 cout<<"\n3.Scaling:";
28 cout<<"\nEnter the option:";
29 cin>>op;
30
31 switch(op)
32 {
33 case 1:
34 cout<<"\nEnter x translation:";
35 cin>>tx;
36 cout<<"\nEnter y translation:";
37 cin>>ty;
38
39 b[0][0]=1;
40 b[0][1]=0;
41 b[0][2]=0;
42
43 b[1][0]=0;
44 b[1][1]=1;
45 b[1][2]=0;
46
47 b[2][0]=tx;
48 b[2][1]=ty;
49 b[2][2]=1;

https://tarikjaber.github.io/Code-to-PDF/ 1/3
10/23/24, 6:19 AM Convert Code to PDF Online: Free Tool for Programming Languages

50
51 break;
52
53 case 2:
54 cout<<"\nEnter rotation angle:";
55 cin>>angle;
56
57 b[0][0]=cos(angle*3.14/180);
58 b[0][1]=sin(angle*3.14/180);
59 b[0][2]=0;
60
61 b[1][0]=-sin(angle*3.14/180);
62 b[1][1]=cos(angle*3.14/180);
63 b[1][2]=0;
64
65 b[2][0]=0;
66 b[2][1]=0;
67 b[2][2]=1;
68
69 break;
70
71 case 3:
72 cout<<"\nEnter x scaling:";
73 cin>>sx;
74 cout<<"\nEnter y scaling:";
75 cin>>sy;
76
77 b[0][0]=sx;
78 b[0][1]=0;
79 b[0][2]=0;
80
81 b[1][0]=0;
82 b[1][1]=sy;
83 b[1][2]=0;
84
85 b[2][0]=0;
86 b[2][1]=0;
87 b[2][2]=1;
88
89 break;
90 }
91
92 initgraph(&gd,&gm,NULL);
93
94 xmax=getmaxx();
95 ymax=getmaxy();
96 xmid=xmax/2;
97 ymid=ymax/2;
98
99 setcolor(1);
100 line(xmid,0,xmid,ymax);

https://tarikjaber.github.io/Code-to-PDF/ 2/3
10/23/24, 6:19 AM Convert Code to PDF Online: Free Tool for Programming Languages

101 line(0,ymid,xmax,ymid);
102 setcolor(4);
103
104 for(i=0;i<8;i=i+2)
105 {
106 line(p1[i]+xmid,ymid-p1[i+1],xmid+p1[i+2],ymid-p1[i+3]);
107 }
108
109 matmul(p1);
110 setcolor(15);
111
112 for(i=0;i<8;i=i+2)
113 {
114 line(xmid+pi[i],ymid-pi[i+1],xmid+pi[i+2],ymid-pi[i+3]);
115 }
116
117 getch();
118 closegraph();
119 return 0;
120 }
121
122 void matmul(float p[10])
123 {
124 int i;
125 for(i=0;i<9;i=i+2)
126 {
127 a[0][0]=p[i];
128 a[0][1]=p[i+1];
129 c[0][0]=a[0][0]*b[0][0]+a[0][1]*b[1][0]+b[2][0];
130 c[0][1]=a[0][0]*b[0][1]+a[0][1]*b[1][1]+b[2][1];
131 pi[i]=c[0][0];
132 pi[i+1]=c[0][1];
133
134 }
135 }
136

https://tarikjaber.github.io/Code-to-PDF/ 3/3

You might also like