-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtwo-dimentional-translation.cpp
56 lines (47 loc) · 1.3 KB
/
two-dimentional-translation.cpp
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
#include <graphics.h>
#include <bits/stdc++.h>
using namespace std;
void draw(vector<int> x, vector<int> y)
{
int n = x.size();
for (int i = 0; i < n; i++)
{
line(x[i], y[i], x[(i + 1) % n], y[(i + 1) % n]);
}
}
void translate(vector<int> &x, vector<int> &y, int tx, int ty)
{
int n = x.size();
for (int i = 0; i < n; i++)
{
x[i] += tx;
y[i] += ty;
}
}
int main()
{
int n; //... Number of vertex of the polygon
cin >> n;
vector<int> x(n), y(n); //... (x,y) coordinates of polygon vertex points
for (int i = 0; i < n; i++)
{
cin >> x[i] >> y[i];
}
int tx, ty; //... Translation factors
cin >> tx >> ty;
int gd = DETECT, gm = DETECT;
initgraph(&gd, &gm, "");
setcolor(WHITE);
draw(x, y); //... The polygon before translation
translate(x, y, tx, ty); //... Applying 2d translation
setcolor(YELLOW);
draw(x, y); //... The polygon after translation
getch();
closegraph();
return 0;
}
/*//... Sample Input-Output:
___________________________________________________________________________________________________________________________________________________________________________________________________________________________
Input:
4 100 100 100 200 200 200 200 100 150 150
*///...