Jpp
JEulerAngle3D.hh
Go to the documentation of this file.
1 #ifndef __JEULERANGLE3D__
2 #define __JEULERANGLE3D__
3 
4 #include <istream>
5 #include <ostream>
6 
7 #include "JTools/JConstants.hh"
8 #include "JIO/JSerialisable.hh"
9 #include "JMath/JMath.hh"
10 
11 #include "JGeometry3D/JAngle3D.hh"
12 #include "JGeometry3D/JVersor3D.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 
19 namespace JGEOMETRY3D {}
20 namespace JPP { using namespace JGEOMETRY3D; }
21 
22 namespace JGEOMETRY3D {
23 
24  using JTOOLS::PI;
25  using JIO::JReader;
26  using JIO::JWriter;
27 
28 
29  /**
30  * Data structure for Euler angles in three dimensions.
31  *
32  * This class implements the JMATH::JMath interface.
33  */
34  class JEulerAngle3D :
35  public JMATH::JMath<JEulerAngle3D>
36  {
37  public:
38  /**
39  * Default constructor.
40  */
42  __alpha(0.0),
43  __beta (0.0),
44  __gamma(0.0)
45  {}
46 
47 
48  /**
49  * Constructor.
50  *
51  * \param alpha alpha angle [rad]
52  * \param beta beta angle [rad]
53  * \param gamma gamma angle [rad]
54  */
55  JEulerAngle3D(const double alpha,
56  const double beta,
57  const double gamma) :
58  __alpha(alpha),
59  __beta (beta),
60  __gamma(gamma)
61  {}
62 
63 
64  /**
65  * Constructor.
66  *
67  * \param angle angle
68  */
69  JEulerAngle3D(const JAngle3D& angle) :
70  __alpha(PI/2),
71  __beta (angle.getTheta()),
72  __gamma(angle.getPhi() + PI/2)
73  {}
74 
75 
76  /**
77  * Constructor.
78  *
79  * \param versor versor
80  */
81  JEulerAngle3D(const JVersor3D& versor) :
82  __alpha(PI/2),
83  __beta (versor.getTheta()),
84  __gamma(versor.getPhi() + PI/2)
85  {}
86 
87 
88  /**
89  * Get Euler angle.
90  *
91  * \return this angle
92  */
94  {
95  return static_cast<const JEulerAngle3D&>(*this);
96  }
97 
98 
99  /**
100  * Set Euler angle.
101  *
102  * \param angle Euler angle
103  */
104  void setEulerAngle(const JEulerAngle3D& angle)
105  {
106  static_cast<JEulerAngle3D&>(*this) = angle;
107  }
108 
109 
110  /**
111  * Negate angle.
112  *
113  * \return this angle
114  */
116  {
117  __alpha = -__alpha;
118  __beta = -__beta;
119  __gamma = -__gamma;
120 
121  return *this;
122  }
123 
124 
125  /**
126  * Add angle.
127  *
128  * \param angle angle
129  * \return this angle
130  */
132  {
133  __alpha += angle.getAlpha();
134  __beta += angle.getBeta();
135  __gamma += angle.getGamma();
136 
137  return *this;
138  }
139 
140 
141  /**
142  * Subtract angle.
143  *
144  * \param angle angle
145  * \return this angle
146  */
148  {
149  __alpha -= angle.getAlpha();
150  __beta -= angle.getBeta();
151  __gamma -= angle.getGamma();
152 
153  return *this;
154  }
155 
156 
157  /**
158  * Scale angle.
159  *
160  * \param factor multiplication factor
161  * \return this angle
162  */
163  JEulerAngle3D& mul(const double factor)
164  {
165  __alpha *= factor;
166  __beta *= factor;
167  __gamma *= factor;
168 
169  return *this;
170  }
171 
172 
173  /**
174  * Scale angle.
175  *
176  * \param factor division factor
177  * \return this angle
178  */
179  JEulerAngle3D& div(const double factor)
180  {
181  __alpha /= factor;
182  __beta /= factor;
183  __gamma /= factor;
184 
185  return *this;
186  }
187 
188 
189  /**
190  * Get alpha angle.
191  *
192  * \return alpha angle
193  */
194  double getAlpha() const
195  {
196  return __alpha;
197  }
198 
199 
200  /**
201  * Get beta angle.
202  *
203  * \return beta angle
204  */
205  double getBeta() const
206  {
207  return __beta;
208  }
209 
210 
211  /**
212  * Get gamma angle.
213  *
214  * \return gamma angle
215  */
216  double getGamma() const
217  {
218  return __gamma;
219  }
220 
221 
222  /**
223  * Read Euler angles from input.
224  *
225  * \param in input stream
226  * \param angle Euler angles
227  * \return input stream
228  */
229  friend inline std::istream& operator>>(std::istream& in, JEulerAngle3D& angle)
230  {
231  in >> angle.__alpha >> angle.__beta >> angle.__gamma;
232 
233  return in;
234  }
235 
236 
237  /**
238  * Write Euler angles to output.
239  *
240  * \param out output stream
241  * \param angle Euler angle
242  * \return output stream
243  */
244  friend inline std::ostream& operator<<(std::ostream& out, const JEulerAngle3D& angle)
245  {
246  out << angle.getAlpha() << ' ' << angle.getBeta() << ' ' << angle.getGamma();
247 
248  return out;
249  }
250 
251 
252  /**
253  * Read Euler angles from input.
254  *
255  * \param in reader
256  * \param angle Euler angles
257  * \return reader
258  */
259  friend inline JReader& operator>>(JReader& in, JEulerAngle3D& angle)
260  {
261  in >> angle.__alpha;
262  in >> angle.__beta;
263  in >> angle.__gamma;
264 
265  return in;
266  }
267 
268 
269  /**
270  * Write Euler angles to output.
271  *
272  * \param out writer
273  * \param angle Euler angles
274  * \return writer
275  */
276  friend inline JWriter& operator<<(JWriter& out, const JEulerAngle3D& angle)
277  {
278  out << angle.__alpha;
279  out << angle.__beta;
280  out << angle.__gamma;
281 
282  return out;
283  }
284 
285 
286  protected:
287  double __alpha;
288  double __beta;
289  double __gamma;
290  };
291 }
292 
293 #endif
JIO::JReader
Interface for binary input.
Definition: JSerialisable.hh:62
JGEOMETRY3D::JEulerAngle3D::add
JEulerAngle3D & add(const JEulerAngle3D &angle)
Add angle.
Definition: JEulerAngle3D.hh:131
JGEOMETRY3D::JEulerAngle3D::sub
JEulerAngle3D & sub(const JEulerAngle3D &angle)
Subtract angle.
Definition: JEulerAngle3D.hh:147
JGEOMETRY3D::JEulerAngle3D::JEulerAngle3D
JEulerAngle3D(const JAngle3D &angle)
Constructor.
Definition: JEulerAngle3D.hh:69
JGEOMETRY3D::JEulerAngle3D::getGamma
double getGamma() const
Get gamma angle.
Definition: JEulerAngle3D.hh:216
JGEOMETRY3D::JEulerAngle3D::JEulerAngle3D
JEulerAngle3D(const JVersor3D &versor)
Constructor.
Definition: JEulerAngle3D.hh:81
JGEOMETRY3D::JVersor3D
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:23
JGEOMETRY3D::JEulerAngle3D::__alpha
double __alpha
Definition: JEulerAngle3D.hh:287
JMATH::JMath
Auxiliary base class for aritmetic operations of derived class types.
Definition: JMath.hh:26
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JSerialisable.hh
JGEOMETRY3D::JEulerAngle3D::getBeta
double getBeta() const
Get beta angle.
Definition: JEulerAngle3D.hh:205
JConstants.hh
JGEOMETRY3D::JEulerAngle3D::__beta
double __beta
Definition: JEulerAngle3D.hh:288
JIO::JWriter
Interface for binary output.
Definition: JSerialisable.hh:130
JAngle3D.hh
JGEOMETRY3D::JEulerAngle3D::operator<<
friend JWriter & operator<<(JWriter &out, const JEulerAngle3D &angle)
Write Euler angles to output.
Definition: JEulerAngle3D.hh:276
JGEOMETRY3D::JEulerAngle3D::getAlpha
double getAlpha() const
Get alpha angle.
Definition: JEulerAngle3D.hh:194
JGEOMETRY3D::JEulerAngle3D::operator>>
friend std::istream & operator>>(std::istream &in, JEulerAngle3D &angle)
Read Euler angles from input.
Definition: JEulerAngle3D.hh:229
JGEOMETRY3D::JEulerAngle3D::getEulerAngle
const JEulerAngle3D & getEulerAngle() const
Get Euler angle.
Definition: JEulerAngle3D.hh:93
JMath.hh
JGEOMETRY3D::JAngle3D
Data structure for angles in three dimensions.
Definition: JAngle3D.hh:31
JGEOMETRY3D::JEulerAngle3D::JEulerAngle3D
JEulerAngle3D(const double alpha, const double beta, const double gamma)
Constructor.
Definition: JEulerAngle3D.hh:55
JGEOMETRY3D::JEulerAngle3D::negate
JEulerAngle3D & negate()
Negate angle.
Definition: JEulerAngle3D.hh:115
JGEOMETRY3D::JEulerAngle3D::setEulerAngle
void setEulerAngle(const JEulerAngle3D &angle)
Set Euler angle.
Definition: JEulerAngle3D.hh:104
JGEOMETRY3D::JEulerAngle3D::mul
JEulerAngle3D & mul(const double factor)
Scale angle.
Definition: JEulerAngle3D.hh:163
JGEOMETRY3D::JEulerAngle3D::JEulerAngle3D
JEulerAngle3D()
Default constructor.
Definition: JEulerAngle3D.hh:41
JTOOLS::PI
static const double PI
Constants.
Definition: JConstants.hh:20
JGEOMETRY3D::JEulerAngle3D::__gamma
double __gamma
Definition: JEulerAngle3D.hh:289
JGEOMETRY3D
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition: JAngle3D.hh:18
JVersor3D.hh
JGEOMETRY3D::JEulerAngle3D
Data structure for Euler angles in three dimensions.
Definition: JEulerAngle3D.hh:34
JGEOMETRY3D::JEulerAngle3D::operator<<
friend std::ostream & operator<<(std::ostream &out, const JEulerAngle3D &angle)
Write Euler angles to output.
Definition: JEulerAngle3D.hh:244
JGEOMETRY3D::JEulerAngle3D::div
JEulerAngle3D & div(const double factor)
Scale angle.
Definition: JEulerAngle3D.hh:179
JGEOMETRY3D::JEulerAngle3D::operator>>
friend JReader & operator>>(JReader &in, JEulerAngle3D &angle)
Read Euler angles from input.
Definition: JEulerAngle3D.hh:259