Jpp  15.0.1-rc.1-highqe
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JVersor3Z.hh
Go to the documentation of this file.
1 #ifndef __JVERSOR3Z__
2 #define __JVERSOR3Z__
3 
4 #include <istream>
5 #include <ostream>
6 #include <limits>
7 #include <cmath>
8 
9 #include "JIO/JSerialisable.hh"
10 #include "JLang/JManip.hh"
11 #include "JMath/JMath.hh"
12 #include "JGeometry2D/JVersor2D.hh"
13 #include "JGeometry3D/JAngle3D.hh"
14 #include "JGeometry3D/JVector3D.hh"
15 #include "JGeometry3D/JVersor3D.hh"
16 
17 
18 /**
19  * \author mdejong
20  */
21 
22 namespace JGEOMETRY3D {}
23 namespace JPP { using namespace JGEOMETRY3D; }
24 
25 namespace JGEOMETRY3D {
26 
27  using JMATH::JMath;
28  using JIO::JReader;
29  using JIO::JWriter;
31 
32 
33  /**
34  * Data structure for normalised vector in positive z-direction.
35  * The member methods getDX() and getDY() refer to the corresponding direction cosines.
36  * Note that the direction cosines may have any value.
37  * The method getDZ() will simply return 0 if the sum of the squares of the direction cosines is larger than 1.
38  */
39  class JVersor3Z :
40  public JMath<JVersor3Z>
41  {
42  public:
43  /**
44  * Default constructor.
45  */
47  __dx(0.0),
48  __dy(0.0)
49  {}
50 
51 
52  /**
53  * Constructor.
54  *
55  * \param dir direction cosines
56  */
57  JVersor3Z(const JVersor2D& dir) :
58  __dx(dir.getDX()),
59  __dy(dir.getDY())
60  {}
61 
62 
63  /**
64  * Constructor.
65  *
66  * \param dx direction cosine dx/dz
67  * \param dy direction cosine dy/dz
68  */
69  JVersor3Z(const double dx,
70  const double dy) :
71  __dx(dx),
72  __dy(dy)
73  {}
74 
75 
76  /**
77  * Get direction.
78  *
79  * \return direction
80  */
81  const JVersor3Z& getDirection() const
82  {
83  return static_cast<const JVersor3Z&>(*this);
84  }
85 
86 
87  /**
88  * Get direction.
89  *
90  * \return direction
91  */
93  {
94  return static_cast<JVersor3Z&>(*this);
95  }
96 
97 
98  /**
99  * Set direction.
100  *
101  * \param direction direction
102  */
103  void setDirection(const JVersor3Z& direction)
104  {
105  static_cast<JVersor3Z&>(*this) = direction;
106  }
107 
108 
109  /**
110  * Get angle.
111  *
112  * \return angle
113  */
114  operator JAngle3D() const
115  {
116  return JAngle3D(getDX(), getDY(), getDZ());
117  }
118 
119 
120  /**
121  * Type conversion operator.
122  *
123  * \return position
124  */
125  operator JVector3D() const
126  {
127  return JVector3D(getDX(), getDY(), getDZ());
128  }
129 
130 
131  /**
132  * Type conversion operator.
133  *
134  * \return direction
135  */
136  operator JVersor3D() const
137  {
138  return JVersor3D(getDX(), getDY(), getDZ());
139  }
140 
141 
142  /**
143  * Get x direction.
144  *
145  * \return x direction
146  */
147  double getDX() const
148  {
149  return __dx;
150  }
151 
152 
153  /**
154  * Get y direction.
155  *
156  * \return y direction
157  */
158  double getDY() const
159  {
160  return __dy;
161  }
162 
163 
164  /**
165  * Get z direction.
166  *
167  * \return z direction
168  */
169  double getDZ() const
170  {
171  const double v = getDX()*getDX() + getDY()*getDY();
172 
173  if (v <= 1.0)
174  return sqrt(1.0 - v);
175  else
176  return 0.0;
177  }
178 
179 
180  /**
181  * Prefix unary minus.
182  *
183  * \return this versor
184  */
186  {
187  __dx = -__dx;
188  __dy = -__dy;
189 
190  return *this;
191  }
192 
193 
194  /**
195  * Addition operator.
196  *
197  * \param value versor
198  * \return this versor
199  */
200  JVersor3Z& add(const JVersor3Z& value)
201  {
202  __dx += value.getDX();
203  __dy += value.getDY();
204 
205  return *this;
206  }
207 
208 
209  /**
210  * Subtraction operator.
211  *
212  * \param value versor
213  * \return this versor
214  */
215  JVersor3Z& sub(const JVersor3Z& value)
216  {
217  __dx -= value.getDX();
218  __dy -= value.getDY();
219 
220  return *this;
221  }
222 
223 
224  /**
225  * Multiplication operator.
226  *
227  * \param value multiplication factor
228  * \return this versor
229  */
230  JVersor3Z& mul(const double value)
231  {
232  __dx *= value;
233  __dy *= value;
234 
235  return *this;
236  }
237 
238 
239  /**
240  * Division operator.
241  *
242  * \param value multiplication factor
243  * \return this versor
244  */
245  JVersor3Z& div(const double value)
246  {
247  __dx /= value;
248  __dy /= value;
249 
250  return *this;
251  }
252 
253 
254  /**
255  * Check equality.
256  *
257  * \param versor versor
258  * \param precision precision
259  * \return true if versors are equal; else false
260  */
261  bool equals(const JVersor3D& versor,
262  const double precision = std::numeric_limits<double>::min()) const
263  {
264  return (fabs(getDX() - versor.getDX()) <= precision &&
265  fabs(getDY() - versor.getDY()) <= precision);
266  }
267 
268 
269  /**
270  * Get dot product.
271  *
272  * \param dir direction
273  * \return dot product
274  */
275  double getDot(const JVersor3Z& dir) const
276  {
277  return
278  getDX() * dir.getDX() +
279  getDY() * dir.getDY() +
280  getDZ() * dir.getDZ();
281  }
282 
283 
284  /**
285  * Get dot product.
286  *
287  * \param angle angle
288  * \return dot product
289  */
290  double getDot(const JAngle3D& angle) const
291  {
292  return
293  getDX() * angle.getDX() +
294  getDY() * angle.getDY() +
295  getDZ() * angle.getDZ();
296  }
297 
298 
299  /**
300  * Get dot product.
301  *
302  * \param pos position
303  * \return dot product
304  */
305  double getDot(const JVector3D& pos) const
306  {
307  return
308  getDX() * pos.getX() +
309  getDY() * pos.getY() +
310  getDZ() * pos.getZ();
311  }
312 
313 
314  /**
315  * Get dot product.
316  *
317  * \param dir direction
318  * \return dot product
319  */
320  double getDot(const JVersor3D& dir) const
321  {
322  return
323  getDX() * dir.getDX() +
324  getDY() * dir.getDY() +
325  getDZ() * dir.getDZ();
326  }
327 
328 
329  /**
330  * Read versor from input.
331  *
332  * \param in input stream
333  * \param versor versor
334  * \return input stream
335  */
336  friend inline std::istream& operator>>(std::istream& in, JVersor3Z& versor)
337  {
338  return in >> versor.__dx >> versor.__dy;
339  }
340 
341 
342  /**
343  * Write versor to output.
344  *
345  * \param out output stream
346  * \param versor versor
347  * \return output stream
348  */
349  friend inline std::ostream& operator<<(std::ostream& out, const JVersor3Z& versor)
350  {
351  const JFormat format(out, getFormat<JVersor3Z>(JFormat_t(9, 6, std::ios::fixed | std::ios::showpos)));
352 
353  return out << format << versor.getDX() << ' ' << format << versor.getDY();
354  }
355 
356 
357  /**
358  * Read versor from input.
359  *
360  * \param in reader
361  * \param versor versor
362  * \return reader
363  */
364  friend inline JReader& operator>>(JReader& in, JVersor3Z& versor)
365  {
366  return in >> versor.__dx >> versor.__dy;
367  }
368 
369 
370  /**
371  * Write versor to output.
372  *
373  * \param out writer
374  * \param versor versor
375  * \return writer
376  */
377  friend inline JWriter& operator<<(JWriter& out, const JVersor3Z& versor)
378  {
379  return out << versor.__dx << versor.__dy;
380  }
381 
382  protected:
383  double __dx;
384  double __dy;
385  };
386 }
387 
388 #endif
friend std::istream & operator>>(std::istream &in, JVersor3Z &versor)
Read versor from input.
Definition: JVersor3Z.hh:336
double getDot(const JVersor3Z &dir) const
Get dot product.
Definition: JVersor3Z.hh:275
Data structure for angles in three dimensions.
Definition: JAngle3D.hh:33
friend JWriter & operator<<(JWriter &out, const JVersor3Z &versor)
Write versor to output.
Definition: JVersor3Z.hh:377
Interface for binary output.
JVersor3Z(const JVersor2D &dir)
Constructor.
Definition: JVersor3Z.hh:57
Auxiliary base class for aritmetic operations of derived class types.
Definition: JMath.hh:110
JVersor3Z & negate()
Prefix unary minus.
Definition: JVersor3Z.hh:185
JVersor3Z & sub(const JVersor3Z &value)
Subtraction operator.
Definition: JVersor3Z.hh:215
double getDot(const JAngle3D &angle) const
Get dot product.
Definition: JVersor3Z.hh:290
JVersor3Z & add(const JVersor3Z &value)
Addition operator.
Definition: JVersor3Z.hh:200
double getDY() const
Get y direction.
Definition: JVersor3Z.hh:158
JVersor3Z & mul(const double value)
Multiplication operator.
Definition: JVersor3Z.hh:230
Auxiliary class to temporarily define format specifications.
Definition: JManip.hh:632
JVersor3Z()
Default constructor.
Definition: JVersor3Z.hh:46
friend std::ostream & operator<<(std::ostream &out, const JVersor3Z &versor)
Write versor to output.
Definition: JVersor3Z.hh:349
double getDot(const JVersor3D &dir) const
Get dot product.
Definition: JVersor3Z.hh:320
Data structure for normalised vector in two dimensions.
Definition: JVersor2D.hh:20
Data structure for vector in three dimensions.
Definition: JVector3D.hh:34
double getDY() const
Get y direction.
Definition: JVersor3D.hh:106
JVersor3Z & div(const double value)
Division operator.
Definition: JVersor3Z.hh:245
double getDX() const
Get x direction.
Definition: JVersor3D.hh:95
double getY() const
Get y position.
Definition: JVector3D.hh:104
void setDirection(const JVersor3Z &direction)
Set direction.
Definition: JVersor3Z.hh:103
Interface for binary input.
JVersor3Z & getDirection()
Get direction.
Definition: JVersor3Z.hh:92
JVersor3Z(const double dx, const double dy)
Constructor.
Definition: JVersor3Z.hh:69
I/O manipulators.
const JVersor3Z & getDirection() const
Get direction.
Definition: JVersor3Z.hh:81
bool equals(const JVersor3D &versor, const double precision=std::numeric_limits< double >::min()) const
Check equality.
Definition: JVersor3Z.hh:261
double getDX() const
Get x direction.
Definition: JVersor3Z.hh:147
double getX() const
Get x position.
Definition: JVector3D.hh:94
Base class for data structures with artithmetic capabilities.
double getDot(const JVector3D &pos) const
Get dot product.
Definition: JVersor3Z.hh:305
double getDZ() const
Get z direction.
Definition: JVersor3Z.hh:169
friend JReader & operator>>(JReader &in, JVersor3Z &versor)
Read versor from input.
Definition: JVersor3Z.hh:364
data_type v[N+1][M+1]
Definition: JPolint.hh:740
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:26
Data structure for normalised vector in positive z-direction.
Definition: JVersor3Z.hh:39
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
Data structure for format specifications.
Definition: JManip.hh:522
double getZ() const
Get z position.
Definition: JVector3D.hh:115
double getDZ() const
Get z direction.
Definition: JVersor3D.hh:117
double getDX() const
Get x direction.
Definition: JAngle3D.hh:108
double getDZ() const
Get z direction.
Definition: JAngle3D.hh:130
double getDY() const
Get y direction.
Definition: JAngle3D.hh:119