-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRay.cpp
More file actions
64 lines (56 loc) · 1.64 KB
/
Copy pathRay.cpp
File metadata and controls
64 lines (56 loc) · 1.64 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
#include "Ray.h"
Ray::Ray(const QPointF &begin, const QPointF &end) {
begin_ = begin;
end_ = end;
if (begin.x() == end.x()) {
if (begin.y() <= end.y()) {
angle_ = M_PI_2;
} else {
angle_ = 3 * M_PI_2;
}
} else if (begin.y() == end.y()) {
if (begin.x() <= end.x()) {
angle_ = 0;
} else {
angle_ = M_PI;
}
} else if((end.x() - begin.x()) > 0) {
if ((end.y() - begin.y()) > 0) {
angle_ = atan((end.y() - begin.y()) / (end.x() - begin.x()));
} else {
angle_ = atan((end.y() - begin.y()) / (end.x() - begin.x())) + 2 * M_PI;
}
} else if((end.x() - begin.x()) < 0) {
if ((end.y() - begin.y()) > 0) {
angle_ = atan((end.y() - begin.y()) / (end.x() - begin.x())) + M_PI;
} else {
angle_ = atan((end.y() - begin.y()) / (end.x() - begin.x())) + M_PI;
}
}
}
Ray Ray::Rotate(double angle) const {
QPointF newEnd(end_.x() * cos(angle) - end_.y() * sin(angle), end_.x() * sin(angle) + end_.y() * cos(angle));
Ray newRay(begin_, newEnd);
return newRay;
}
QPointF Ray::getBegin() const {
return begin_;
}
QPointF Ray::getEnd() const {
return end_;
}
double Ray::getAngle() const {
return angle_;
}
void Ray::setBegin(QPointF newBegin) {
Ray temp = Ray(newBegin, end_);
*this = temp;
}
void Ray::setEnd(QPointF newEnd) {
Ray temp = Ray(begin_, newEnd);
*this = temp;
}
void Ray::setAngle(double angle) {
Ray temp = this->Rotate(angle - angle_);
*this = temp;
}