-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransform.cpp
101 lines (99 loc) · 1.72 KB
/
transform.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
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
#include <iostream>
#include <cmath>
#include <iomanip>
#define cout std::cout
#define cin std::cin
struct Vector
{
double x, y;
void translate(int x2, int y2)
{
x += x2;
y += y2;
}
void reflect(char ch)
{
if (ch == 'x')
{
y *= -1;
}
if (ch == 'y')
{
x *= -1;
}
}
void rotate(int deg)
{
double alpha = acos(x / hypotf(x, y)) * 180 / M_PI;
double beta = asin(y / hypotf(x, y)) * 180 / M_PI;
double r = hypotf(x, y);
x = r * cos((alpha + deg) * M_PI / 180);
y = r * sin((beta + deg) * M_PI / 180);
}
};
int main()
{
Vector v1;
cout << "Tentukan vektor: ";
while (!(cin >> v1.x >> v1.y))
{
cout << "itu bukan vektor\n";
cin.clear();
cin.ignore();
}
cout << "Tentukan Transformasi:\n";
cout << "1. Translasi\n"
<< "2. Refleksi\n"
<< "3. Rotasi\n";
int ch;
while (!(cin >> ch) or ch < 1 or ch > 3)
{
cout << "Gunakan angka antara 1, 2, atau 3.\n";
cin.clear();
cin.ignore();
}
int x2, y2;
char k;
int deg;
switch (ch)
{
case 1:
cout << "Masukkan koordinat pangkal yang baru: ";
while (!(cin >> x2 >> y2))
{
cout << "Salah ";
cin.clear();
cin.ignore();
}
v1.translate(x2, y2);
cout << "Koordinat setelah translasi\n"
<< v1.x << ", " << v1.y;
break;
case 2:
cout << "berdasarkan sumbu x atau y?\n";
cin >> k;
while ((k != 'x' and k != 'y'))
{
cout << "berdasarkan sumbu x atau y?\n";
cin >> k;
}
v1.reflect(k);
cout << "Hasil Refleksi\n"
<< v1.x << ", " << v1.y;
break;
case 3:
cout << "Masukkan derajat\n";
while (!(cin >> deg))
{
cout << "Masukkan derajat\n";
cin.clear();
cin.ignore();
}
v1.rotate(deg);
cout << "Hasil rotasi\n";
cout << std::fixed;
cout << v1.x << ", " << v1.y;
break;
}
return 0;
}