-
Notifications
You must be signed in to change notification settings - Fork 19
/
PointCart.cpp
executable file
·91 lines (72 loc) · 1.45 KB
/
PointCart.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
86
87
88
89
90
91
#include <PointCart.h>
PointCart::PointCart(const double& x, const double& y, const double& z)
{
m_x = x;
m_y = y;
m_z = z;
}
PointCart::PointCart(const Point& p)
{
m_x = p.getX();
m_y = p.getY();
m_z = p.getZ();
}
PointCart::~PointCart()
{
}
PointCart PointCart::operator=(const Point& p)
{
m_x = p.getX();
m_y = p.getY();
m_z = p.getZ();
return *this;
}
PointCart& PointCart::operator+=(const Point& p)
{
m_x += p.getX();
m_y += p.getY();
m_z += p.getZ();
return *this;
}
PointCart& PointCart::operator-=(const Point& p)
{
m_x -= p.getX();
m_y -= p.getY();
m_z -= p.getZ();
return *this;
}
PointCart operator+(const PointCart& a, const Point& b)
{
PointCart copy(a);
copy+=b;
return copy;
}
PointCart operator-(const PointCart& a, const Point& b)
{
PointCart copy(a);
copy-=b;
return copy;
}
double PointCart::getR() const
{
return std::sqrt(m_x*m_x + m_y*m_y + m_z*m_z);
}
double PointCart::getTheta() const
{
if (m_x > 0.0 && m_y >= 0.0)
return std::atan(m_y/m_x);
if (m_x == 0.0 && m_y > 0.0)
return Constants::pi / 2.0;
if (m_x < 0.0)
return Constants::pi + std::atan(m_y/m_x);
if (m_x == 0.0 && m_y < 0.0)
return 3.0 * Constants::pi / 2.0;
if (m_x > 0.0 && m_y < 0.0)
return Constants::twopi + std::atan(m_y/m_x);
return 0.0;
}
double PointCart::getPhi() const
{
// TODO
return 0.0;
}