-
Notifications
You must be signed in to change notification settings - Fork 19
/
PointPol.cpp
executable file
·85 lines (67 loc) · 1.35 KB
/
PointPol.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
#include <PointPol.h>
PointPol::PointPol(double r, double theta, double phi)
{
m_r = r;
m_theta = theta;
m_phi = phi;
}
PointPol::PointPol(const Point& p)
{
m_r = p.getR();
m_theta = p.getTheta();
m_phi = p.getPhi();
}
PointPol::~PointPol()
{
}
PointPol PointPol::operator=(const Point& p)
{
m_r = p.getR();
m_theta = p.getTheta();
m_phi = p.getPhi();
return *this;
}
PointPol& PointPol::operator+=(const Point& p)
{
// Create cartesian copy of point to use adding operator
PointCart tmp(*this);
tmp+=p;
// Reconvert to polar point
PointPol copy(tmp);
*this = copy;
return *this;
}
PointPol& PointPol::operator-=(const Point& p)
{
// Create cartesian copy of point to use substraction operator
PointCart tmp(*this);
tmp-=p;
// Reconvert to polar point
PointPol copy(tmp);
*this = copy;
return *this;
}
PointPol operator+(const PointPol& a, const Point& b)
{
PointPol copy(a);
copy+=b;
return copy;
}
PointPol operator-(const PointPol& a, const Point& b)
{
PointPol copy(a);
copy-=b;
return copy;
}
double PointPol::getX() const
{
return m_r * std::cos(m_theta) * std::cos(m_phi);
}
double PointPol::getY() const
{
return m_r * std::sin(m_theta) * std::cos(m_phi);
}
double PointPol::getZ() const
{
return m_r * std::sin(m_phi);
}