-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1805007_Rotation.cpp
80 lines (62 loc) · 2.07 KB
/
1805007_Rotation.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
#include "1805007_Rotation.h"
#include <cmath>
#define RAD(x) (x * acos(-1.0) / 180.0)
Rotation::Rotation() : Rotation(0, 0, 0, 0) {}
Rotation::Rotation(double angle, double ax, double ay, double az) : angle{angle}, ax{ax}, ay{ay}, az{az} {
Point a(ax, ay, az);
a.normalize();
Point c1, c2, c3;
c1 = R(Point(1, 0, 0), a, angle);
c2 = R(Point(0, 1, 0), a, angle);
c3 = R(Point(0, 0, 1), a, angle);
double m[][4] = {{c1.getPx(), c2.getPx(), c3.getPx(), 0}, {c1.getPy(), c2.getPy(), c3.getPy(), 0}, {c1.getPz(), c2.getPz(), c3.getPz(), 0}, {0, 0, 0, 1}};
matrix = Matrix(4, 4, (const double *) m);
}
Rotation::Rotation(const Rotation &rotation) : Rotation(rotation.angle, rotation.ax, rotation.ay, rotation.az) {}
Rotation &Rotation::operator=(const Rotation &rhs) {
angle = rhs.angle;
ax = rhs.ax;
ay = rhs.ay;
az = rhs.az;
matrix = rhs.matrix;
return *this;
}
double Rotation::getAngle() const {
return angle;
}
double Rotation::getAx() const {
return ax;
}
double Rotation::getAy() const {
return ay;
}
double Rotation::getAz() const {
return az;
}
Matrix Rotation::getMatrix() const {
return matrix;
}
void Rotation::setAngle(double angle) {
(*this) = Rotation(angle, ax, ay, az);
}
void Rotation::setAx(double ax) {
(*this) = Rotation(angle, ax, ay, az);
}
void Rotation::setAy(double ay) {
(*this) = Rotation(angle, ax, ay, az);
}
void Rotation::setAz(double az) {
(*this) = Rotation(angle, ax, ay, az);
}
Point Rotation::R(const Point &x, const Point &a, double angle) {
return cos(RAD(angle)) * x + (1 - cos(RAD(angle))) * (Point::dot(a, x)) * a + sin(RAD(angle)) * (a * x);
}
ostream &operator<<(ostream &os, const Rotation &rotation) {
os << fixed << setprecision(7) << rotation.angle << " " << rotation.ax << " " << rotation.ay << " " << rotation.az;
return os;
}
istream &operator>>(istream &is, Rotation &rotation) {
is >> rotation.angle >> rotation.ax >> rotation.ay >> rotation.az;
rotation = Rotation(rotation.angle, rotation.ax, rotation.ay, rotation.az);
return is;
}