-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLab 6_Transformation.c
More file actions
161 lines (120 loc) · 2.38 KB
/
Copy pathLab 6_Transformation.c
File metadata and controls
161 lines (120 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
#define PI 3.141592653589793
void init()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
}
void close()
{
getch();
closegraph();
}
void draw(int box[4][2])
{
int i, j;
for (i = 0; i < 4; i++)
{
j = (i + 1)%4;
line(box[i][0], box[i][1], box[j][0], box[j][1]);
}
}
void translate(int box[4][2])
{
int tx, ty, i;
int t_box[4][2];
clrscr();
printf("Enter tx and ty: ");
scanf("%d%d", &tx, &ty);
for (i = 0; i < 4; i++)
{
t_box[i][0] = box[i][0] + tx;
t_box[i][1] = box[i][1] + ty;
}
init();
setcolor(WHITE);
draw(box);
setcolor(RED);
draw(t_box);
close();
}
void scale(int box[4][2])
{
int sx, sy, i;
int s_box[4][2];
clrscr();
printf("Enter sx and sy: ");
scanf("%d%d", &sx, &sy);
for (i = 0; i < 4; i++)
{
s_box[i][0] = box[i][0] - 150;
s_box[i][1] = box[i][1] - 150;
}
for (i = 0; i < 4; i++)
{
s_box[i][0] = s_box[i][0]*sx;
s_box[i][1] = s_box[i][1]*sy;
}
for (i = 0; i < 4; i++)
{
s_box[i][0] = s_box[i][0] + 150;
s_box[i][1] = s_box[i][1] + 150;
}
init();
setcolor(WHITE);
draw(box);
setcolor(RED);
draw(s_box);
close();
}
void rotate(int box[4][2])
{
float ang, temp_x, temp_y;
int i, r_box[4][2];
clrscr();
printf("Enter angle to rotate: ");
scanf("%f", &ang);
for (i = 0; i < 4; i++)
{
r_box[i][0] = box[i][0] - 150;
r_box[i][1] = box[i][1] - 150;
}
for (i = 0; i < 4; i++)
{
temp_x = r_box[i][0];
temp_y = r_box[i][1];
r_box[i][0] = temp_x*cos(ang) - temp_y*sin(ang);
r_box[i][1] = temp_x*sin(ang) + temp_y*cos(ang);
}
for (i = 0; i < 4; i++)
{
r_box[i][0] = r_box[i][0] + 150;
r_box[i][1] = r_box[i][1] + 150;
}
init();
setcolor(WHITE);
draw(box);
setcolor(RED);
draw(r_box);
close();
}
int main()
{
int box[4][2] = {
{100, 100},
{200, 100},
{200, 200},
{100, 200}
};
init();
setcolor(WHITE);
draw(box);
close();
translate(box);
scale(box);
rotate(box);
return 0;
}