A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
angles.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011, 2012 CTTC
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Nicola Baldo <nbaldo@cttc.es>
18 */
19
20#ifndef ANGLES_H
21#define ANGLES_H
22
23#include <ns3/vector.h>
24
25#include <vector>
26
27namespace ns3
28{
29
30/**
31 * \brief converts degrees to radians
32 *
33 * \param degrees the angle in degrees
34 * \return the angle in radians
35 */
36double DegreesToRadians(double degrees);
37
38/**
39 * \brief converts degrees to radians
40 *
41 * \param degrees the angles in degrees
42 * \return the angles in radians
43 */
44std::vector<double> DegreesToRadians(const std::vector<double>& degrees);
45
46/**
47 * \brief converts radians to degrees
48 *
49 * \param radians the angle in radians
50 * \return the angle in degrees
51 */
52double RadiansToDegrees(double radians);
53
54/**
55 * \brief converts radians to degrees
56 *
57 * \param radians the angles in radians
58 * \return the angles in degrees
59 */
60std::vector<double> RadiansToDegrees(const std::vector<double>& radians);
61
62/**
63 * \brief Wrap angle in [0, 360)
64 *
65 * \param a the angle in degrees
66 * \return the wrapped angle in degrees
67 */
68double WrapTo360(double a);
69
70/**
71 * \brief Wrap angle in [-180, 180)
72 *
73 * \param a the angle in degrees
74 * \return the wrapped angle in degrees
75 */
76double WrapTo180(double a);
77
78/**
79 * \brief Wrap angle in [0, 2*M_PI)
80 *
81 * \param a the angle in radians
82 * \return the wrapped angle in radians
83 */
84double WrapTo2Pi(double a);
85
86/**
87 * \brief Wrap angle in [-M_PI, M_PI)
88 *
89 * \param a the angle in radians
90 * \return the wrapped angle in radians
91 */
92double WrapToPi(double a);
93
94/**
95 *
96 * Class holding the azimuth and inclination angles of spherical coordinates.
97 * The notation is the one used in "Antenna Theory - Analysis
98 * and Design", C.A. Balanis, Wiley, 2nd Ed., section 2.2 "Radiation pattern".
99 * This notation corresponds to the standard spherical coordinates, with azimuth
100 * measured counterclockwise in the x-y plane off the x-axis, and
101 * inclination measured off the z-axis.
102 * Azimuth is consistently normalized to be in [-M_PI, M_PI).
103 *
104 * ^
105 * z |
106 * |_ inclination
107 * | \
108 * | /|
109 * |/ | y
110 * +-------->
111 * / \|
112 * /___/
113 * x / azimuth
114 * |/
115 *
116 */
118{
119 public:
120 /**
121 * This constructor allows to specify azimuth and inclination.
122 * Inclination must be in [0, M_PI], while azimuth is
123 * automatically normalized in [-M_PI, M_PI)
124 *
125 * \param azimuth the azimuth angle in radians
126 * \param inclination the inclination angle in radians
127 */
128 Angles(double azimuth, double inclination);
129
130 /**
131 * This constructor will initialize azimuth and inclination by converting the
132 * given 3D vector from cartesian coordinates to spherical coordinates
133 * Note: azimuth and inclination angles for a zero-length vector are not defined
134 * and are thus initialized to NAN
135 *
136 * \param v the 3D vector in cartesian coordinates
137 *
138 */
139 Angles(Vector v);
140
141 /**
142 * This constructor initializes an Angles instance with the angles
143 * of the spherical coordinates of point v respect to point o
144 *
145 * \param v the point (in cartesian coordinates) for which the angles are determined
146 * \param o the origin (in cartesian coordinates) of the spherical coordinate system
147 *
148 */
149 Angles(Vector v, Vector o);
150
151 /**
152 * Setter for azimuth angle
153 *
154 * \param azimuth angle in radians
155 */
156 void SetAzimuth(double azimuth);
157
158 /**
159 * Setter for inclination angle
160 *
161 * \param inclination angle in radians. Must be in [0, M_PI]
162 */
163 void SetInclination(double inclination);
164
165 /**
166 * Getter for azimuth angle
167 *
168 * \return azimuth angle in radians
169 */
170 double GetAzimuth() const;
171
172 /**
173 * Getter for inclination angle
174 *
175 * \return inclination angle in radians
176 */
177 double GetInclination() const;
178
179 // friend methods
180 /**
181 * \brief Stream insertion operator.
182 *
183 * \param [in] os The reference to the output stream.
184 * \param [in] a The angle.
185 * \returns The reference to the output stream.
186 */
187 friend std::ostream& operator<<(std::ostream& os, const Angles& a);
188 /**
189 * \brief Stream extraction operator.
190 *
191 * \param [in] is The reference to the input stream.
192 * \param [out] a The angle.
193 * \returns The reference to the input stream.
194 */
195 friend std::istream& operator>>(std::istream& is, Angles& a);
196
197 static bool m_printDeg; //!< flag for printing in radians or degrees units
198
199 private:
200 /**
201 * Default constructor is disabled
202 */
203 Angles();
204
205 /**
206 * Normalize the angle azimuth angle range between in [-M_PI, M_PI)
207 * while checking if the angle is valid, i.e., finite and within
208 * the bounds.
209 *
210 * Note: while an arbitrary value for the azimuth angle is valid
211 * and can be wrapped in [-M_PI, M_PI), an inclination angle outside
212 * the [0, M_PI] range can be ambiguous and is thus not valid.
213 */
214 void NormalizeAngles();
215
216 /**
217 * Check if Angle is valid or not
218 * Warns the user if the Angle is undefined (non-finite azimuth or inclination),
219 * throws an assert if the inclination angle is invalid (not in [0, M_PI])
220 */
221 void CheckIfValid() const;
222
223 double m_azimuth; //!< the azimuth angle in radians
224 double m_inclination; //!< the inclination angle in radians
225};
226
227} // namespace ns3
228
229#endif // ANGLES_H
Class holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:118
void NormalizeAngles()
Normalize the angle azimuth angle range between in [-M_PI, M_PI) while checking if the angle is valid...
Definition: angles.cc:252
double m_inclination
the inclination angle in radians
Definition: angles.h:224
double GetInclination() const
Getter for inclination angle.
Definition: angles.cc:246
friend std::istream & operator>>(std::istream &is, Angles &a)
Stream extraction operator.
Definition: angles.cc:183
static bool m_printDeg
flag for printing in radians or degrees units
Definition: angles.h:197
void SetAzimuth(double azimuth)
Setter for azimuth angle.
Definition: angles.cc:226
Angles()
Default constructor is disabled.
Definition: angles.cc:194
void SetInclination(double inclination)
Setter for inclination angle.
Definition: angles.cc:233
double m_azimuth
the azimuth angle in radians
Definition: angles.h:223
double GetAzimuth() const
Getter for azimuth angle.
Definition: angles.cc:240
friend std::ostream & operator<<(std::ostream &os, const Angles &a)
Stream insertion operator.
Definition: angles.cc:159
void CheckIfValid() const
Check if Angle is valid or not Warns the user if the Angle is undefined (non-finite azimuth or inclin...
Definition: angles.cc:266
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double WrapToPi(double a)
Wrap angle in [-M_PI, M_PI)
Definition: angles.cc:138
double WrapTo180(double a)
Wrap angle in [-180, 180)
Definition: angles.cc:96
double WrapTo360(double a)
Wrap angle in [0, 360)
Definition: angles.cc:75
double DegreesToRadians(double degrees)
converts degrees to radians
Definition: angles.cc:39
double WrapTo2Pi(double a)
Wrap angle in [0, 2*M_PI)
Definition: angles.cc:117
double RadiansToDegrees(double radians)
converts radians to degrees
Definition: angles.cc:45