-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransforms.cpp
More file actions
111 lines (100 loc) · 3.41 KB
/
Transforms.cpp
File metadata and controls
111 lines (100 loc) · 3.41 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
// --------------------------------------------------------------------------------------------------------------------
// Developer -- Eddie Gyger *
// Course ----- CS3233 *
// Project ---- Homework #3 *
// Due Date --- 10/26/2020 *
// *
// Do-It-Yourself: This program performs the three fundamental transforms on a given coordinate. *
//---------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <cmath>
using namespace std;
//Multipy 3x3 Matrix by 1x3 Vector
void calculateVector(float matrix[3][3], float vector[3]) {
float result[3] = { 0,0,0 };
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
result[i] += matrix[i][j] * vector[j];
}
}
cout << endl;
cout << "X: " << vector[0] << endl << endl;
cout << "Y: " << vector[1] << endl << endl;
cout << "X prime: " << result[0] << endl << endl;
cout << "Y prime: " << result[1] << endl << endl;
}
//Take translation input and build translation matrix
void translate(float * vector) {
float xTranslate;
float yTranslate;
system("cls");
cout << "Enter the value by which to translate the X coordinate: " << endl;
cin >> xTranslate;
cout << endl << "Enter the value by which to translate the Y coordinate: " << endl;
cin >> yTranslate;
float translateMatrix[3][3] = { 1, 0, xTranslate, 0, 1, yTranslate, 0, 0, 1 };
cout << "\nTranslated:\n";
calculateVector(translateMatrix, vector);
}
//Take scale factor input and build scaling matrix
void scale(float * vector) {
float xScaleFactor;
float yScaleFactor;
system("cls");
cout << "Enter the scale factor for X: " << endl;
cin >> xScaleFactor;
cout << "Enter the scale factor for Y: " << endl;
cin >> yScaleFactor;
float scaleMatrix[3][3] = {xScaleFactor, 0, 0, 0, yScaleFactor, 0, 0, 0, 1 };
cout << "\nScaled:\n";
calculateVector(scaleMatrix, vector);
}
//Take rotation angle input and build rotation matrix
void rotate(float * vector) {
float theta;
float PI = 2 * acosf(0.0);
system("cls");
cout << "Enter the angle by which you would like to rotate (Theta)" << endl;
cin >> theta;
//convert to radians
theta *= PI / 180.0;
float rotateMatrix[3][3] = { cosf(theta), (-1 * sinf(theta)), 0, sinf(theta), cosf(theta), 0, 0, 0, 1 };
cout << "\nRotated:\n";
calculateVector(rotateMatrix, vector);
}
int main()
{
float inputVector[3] = { 1,1,1 };
char input = 'a';
//Get coordinate
cout << "Enter the value for X: " << endl;
cin >> inputVector[0];
cout << "Enter the value for Y: " << endl;
cin >> inputVector[1];
//While exit is not chosen display menu and take menu choice input
while (input != '5') {
system("cls");
cout << "Enter the number of the desired operation:\n\n1. Translate\n2. Scale\n3. Rotate\n4. Change Coordinate\n5. Exit\n";
cin >> input;
if (input == '1') {
translate(inputVector);
}
else if (input == '2') {
scale(inputVector);
}
else if (input == '3') {
rotate(inputVector);
}
else if (input == '4') {
system("cls");
cout << "Enter the value for X: " << endl;
cin >> inputVector[0];
cout << "Enter the value for Y: " << endl;
cin >> inputVector[1];
}
else if (input == '5') {
return 0;
}
system("PAUSE");
}
}