Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
CartesianVector.cc
Go to the documentation of this file.
1
10
11#include <limits>
12
13namespace pandora
14{
15
17{
18 const float magnitudesSquared(this->GetMagnitudeSquared() * rhs.GetMagnitudeSquared());
19
20 if (magnitudesSquared < std::numeric_limits<float>::epsilon())
21 throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
22
23 float cosTheta = this->GetDotProduct(rhs) / std::sqrt(magnitudesSquared);
24
25 if (cosTheta > 1.f)
26 {
27 cosTheta = 1.f;
28 }
29 else if (cosTheta < -1.f)
30 {
31 cosTheta = -1.f;
32 }
33
34 return cosTheta;
35}
36
37//------------------------------------------------------------------------------------------------------------------------------------------
38
39void CartesianVector::GetSphericalCoordinates(float &radius, float &phi, float &theta) const
40{
41 const float magnitude(this->GetMagnitude());
42
43 if (std::fabs(magnitude) < std::numeric_limits<float>::epsilon())
44 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
45
46 radius = magnitude;
47 phi = std::atan2(m_y, m_x);
48 theta = std::acos(m_z / radius);
49}
50
51//------------------------------------------------------------------------------------------------------------------------------------------
52
53void CartesianVector::GetCylindricalCoordinates(float &radius, float &phi, float &z) const
54{
55 const float magnitude(this->GetMagnitude());
56
57 if (std::fabs(magnitude) < std::numeric_limits<float>::epsilon())
58 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
59
60 radius = std::sqrt(m_y * m_y + m_x * m_x);
61 phi = std::atan2(m_y, m_x);
62 z = m_z;
63}
64
65//------------------------------------------------------------------------------------------------------------------------------------------
66
68{
69 const float magnitude(this->GetMagnitude());
70
71 if (std::fabs(magnitude) < std::numeric_limits<float>::epsilon())
72 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
73
74 return CartesianVector(m_x / magnitude, m_y / magnitude, m_z / magnitude);
75}
76
77//------------------------------------------------------------------------------------------------------------------------------------------
78//------------------------------------------------------------------------------------------------------------------------------------------
79
80std::ostream &operator<<(std::ostream & stream, const CartesianVector& cartesianVector)
81{
82 stream << " x: " << cartesianVector.GetX()
83 << " y: " << cartesianVector.GetY()
84 << " z: " << cartesianVector.GetZ()
85 << " length: " << cartesianVector.GetMagnitude();
86
87 return stream;
88}
89
90} // namespace pandora
Header file for the cartesian vector class.
CartesianVector class.
float m_y
The y coordinate.
float GetCosOpeningAngle(const CartesianVector &rhs) const
Get the cosine of the opening angle of the cartesian vector with respect to a second cartesian vector...
float GetMagnitudeSquared() const
Get the magnitude squared.
float GetX() const
Get the cartesian x coordinate.
void GetSphericalCoordinates(float &radius, float &phi, float &theta) const
Get the spherical coordinates of the cartesian vector.
float m_x
The x coordinate.
CartesianVector GetUnitVector() const
Get a unit vector in the direction of the cartesian vector.
float GetZ() const
Get the cartesian z coordinate.
float GetDotProduct(const CartesianVector &rhs) const
Get the dot product of the cartesian vector with a second cartesian vector.
float GetMagnitude() const
Get the magnitude.
float GetY() const
Get the cartesian y coordinate.
float m_z
The z coordinate.
void GetCylindricalCoordinates(float &radius, float &phi, float &z) const
Get the cylindrical coordinates of the cartesian vector (x/y .. radius, z .. z)
StatusCodeException class.
std::ostream & operator<<(std::ostream &stream, const CartesianVector &cartesianVector)
Operator to dump cartesian vector properties to an ostream.