-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMatrix.cpp
43 lines (33 loc) · 1.14 KB
/
Matrix.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
#include "Matrix.h"
#include "Vector.h"
#include "Point.h"
#include "Polygon.h"
#include <cmath>
#include <vector>
using namespace std;
Point Matrix::rotateX(const Point& p, double angle) {
return Point(p.x, p.y * cos(angle) - p.z * sin(angle), p.y * sin(angle) + p.z * cos(angle));
}
Point Matrix::rotateY(const Point& p, double angle) {
return Point(p.x * cos(angle) + p.z * sin(angle), p.y, -p.x * sin(angle) + p.z * cos(angle));
}
Vector Matrix::rotateX(const Vector& v, double angle) {
return Vector(v.x, v.y * cos(angle) - v.z * sin(angle), v.y * sin(angle) + v.z * cos(angle));
}
Vector Matrix::rotateY(const Vector& v, double angle) {
return Vector(v.x * cos(angle) + v.z * sin(angle), v.y, -v.x * sin(angle) + v.z * cos(angle));
}
Polygon Matrix::rotateX(const Polygon& poly, double angle) {
vector<Point> newVertices;
for (Point p : poly.vertices) {
newVertices.push_back(Matrix::rotateX(p, angle));
}
return Polygon(newVertices);
}
Polygon Matrix::rotateY(const Polygon& poly, double angle) {
vector<Point> newVertices;
for (Point p : poly.vertices) {
newVertices.push_back(Matrix::rotateY(p, angle));
}
return Polygon(newVertices);
}