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