Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JOmega3D.hh
Go to the documentation of this file.
1 #ifndef __JOMEGA3D__
2 #define __JOMEGA3D__
3 
4 #include <cmath>
5 #include <vector>
6 
7 #include "JTools/JConstants.hh"
8 #include "JTools/JAngleRange.hh"
12 
13 
14 /**
15  * \author mdejong
16  */
17 
18 namespace JGEOMETRY3D {}
19 namespace JPP { using namespace JGEOMETRY3D; }
20 
21 namespace JGEOMETRY3D {
22 
23  using JTOOLS::PI;
24  using JTOOLS::JAngleRange;
25 
26 
27  /**
28  * Base class for direction set.
29  */
30  struct JOmega3D_t :
31  public std::vector<JAngle3D>
32  {
33  /**
34  * Get index of direction closest to given direction.
35  *
36  * \param dir direction
37  * \return index (-1 if error)
38  */
39  int find(const JAngle3D& dir) const
40  {
41  double dot = -1.0;
42  int index = -1;
43 
44  for (const_iterator i = this->begin(); i != this->end(); ++i) {
45 
46  const double x = dir.getDot(*i);
47 
48  if (x > dot) {
49  dot = x;
50  index = std::distance(this->begin(), i);
51  }
52  }
53 
54  return index;
55  }
56  };
57 
58 
59  /**
60  * Direction set covering (part of) solid angle.
61  */
62  class JOmega3D :
63  public JOmega3D_t
64  {
65  public:
66  /**
67  * Default constructor.
68  */
70  JOmega3D_t()
71  {}
72 
73 
74  /**
75  * Constructor.
76  *
77  * \param dir direction
78  */
79  JOmega3D(const JAngle3D& dir) :
80  JOmega3D_t()
81  {
82  push_back(dir);
83  }
84 
85 
86  /**
87  * Constructor.
88  *
89  * \param grid angular step size [rad]
90  */
91  JOmega3D(const double grid) :
92  JOmega3D_t()
93  {
94  configure(JAngle3D(0.0,0.0), JAngleRange(0.0,PI), grid);
95  }
96 
97 
98 
99  /**
100  * Constructor.
101  *
102  * \param dir principal direction
103  * \param theta polar angle range [rad]
104  * \param grid angular step size [rad]
105  */
106  JOmega3D(const JAngle3D& dir,
107  const JAngleRange& theta,
108  const double grid) :
109  JOmega3D_t()
110  {
111  configure(dir, theta, grid);
112  }
113 
114 
115  /**
116  * Configure direction set.
117  *
118  * \param dir principal direction
119  * \param theta polar angle range [rad]
120  * \param grid angular step size [rad]
121  */
122  void configure(const JAngle3D& dir,
123  const JAngleRange& theta,
124  const double grid)
125  {
126  clear();
127 
128  // sanity checks
129 
130  double thetaMin = theta.getLowerLimit();
131  double thetaMax = theta.getUpperLimit();
132 
133  if (thetaMin < 0.0) { thetaMin = 0.0; }
134  if (thetaMin > PI) { thetaMin = PI; }
135  if (thetaMax < 0.0) { thetaMax = 0.0; }
136  if (thetaMax > PI) { thetaMax = PI; }
137 
138  if (thetaMax > thetaMin) {
139 
140  const JRotation3D R(dir);
141 
142  const double rad = thetaMax - thetaMin;
143  const double bin = rad / floor(rad/(1.4*grid) + 0.5); // polar angle step size
144  const double unit = 2.0 * sqrt(1.0 - cos(grid)); // azimuth angle unit step size
145 
146  for (double theta = thetaMin; theta < thetaMax + 0.5*bin; theta += bin) {
147 
148  double step;
149 
150  if (theta > 0.5*bin && PI - theta > 0.5*bin)
151  step = PI / floor(PI*sin(theta)/unit + 0.5); // polar angle dependent step size
152  else
153  step = 2.0*PI; // pole
154 
155  for (double phi = 0.0; phi < 2.0*PI - 0.5*step; phi += step) {
156  push_back(JDirection3D(JAngle3D(theta,phi)).rotate_back(R));
157  }
158  }
159  }
160  }
161  };
162 }
163 
164 #endif
Data structure for angles in three dimensions.
Definition: JAngle3D.hh:30
void configure(const JAngle3D &dir, const JAngleRange &theta, const double grid)
Configure direction set.
Definition: JOmega3D.hh:122
JOmega3D(const JAngle3D &dir, const JAngleRange &theta, const double grid)
Constructor.
Definition: JOmega3D.hh:106
JOmega3D()
Default constructor.
Definition: JOmega3D.hh:69
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:32
JRange< double > JAngleRange
Type definition for angle range.
Definition: JAngleRange.hh:19
double getDot(const JAngle3D &angle) const
Get dot product.
Definition: JAngle3D.hh:225
Rotation matrix.
Definition: JRotation3D.hh:108
static const double PI
Constants.
Definition: JConstants.hh:20
Direction set covering (part of) solid angle.
Definition: JOmega3D.hh:62
Constants.
JOmega3D(const double grid)
Constructor.
Definition: JOmega3D.hh:91
int find(const JAngle3D &dir) const
Get index of direction closest to given direction.
Definition: JOmega3D.hh:39
Base class for direction set.
Definition: JOmega3D.hh:30
JOmega3D(const JAngle3D &dir)
Constructor.
Definition: JOmega3D.hh:79