Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JOmega2D.hh
Go to the documentation of this file.
1#ifndef __JOMEGA2D__
2#define __JOMEGA2D__
3
4#include <cmath>
5#include <vector>
6
7#include "JMath/JConstants.hh"
8
11
12
13/**
14 * \author mdejong
15 */
16
17namespace JGEOMETRY2D {}
18namespace JPP { using namespace JGEOMETRY2D; }
19
20namespace JGEOMETRY2D {
21
22 using JMATH::PI;
23
24
25 /**
26 * Base class for direction set.
27 */
28 struct JOmega2D_t :
29 public std::vector<JAngle2D>
30 {
31 /**
32 * Get index of direction closest to given direction.
33 *
34 * \param dir direction
35 * \return index (-1 if error)
36 */
37 int find(const JAngle2D& dir) const
38 {
39 double dot = -1.0;
40 int index = -1;
41
42 for (const_iterator i = this->begin(); i != this->end(); ++i) {
43
44 const double x = dir.getDot(*i);
45
46 if (x > dot) {
47 dot = x;
48 index = std::distance(this->begin(), i);
49 }
50 }
51
52 return index;
53 }
54 };
55
56
57 /**
58 * Direction set covering (part of) circle.
59 */
60 class JOmega2D :
61 public JOmega2D_t
62 {
63 public:
64 /**
65 * Default constructor.
66 */
69 {}
70
71
72 /**
73 * Constructor.
74 *
75 * \param grid angular spacing [rad]
76 */
77 JOmega2D(const double grid) :
79 {
80 configure(JAngle2D(0.0), PI, grid);
81 }
82
83
84
85 /**
86 * Constructor.
87 *
88 * \param dir principal direction
89 * \param phiMax maximal angle [rad]
90 * \param grid angular spacing [rad]
91 */
92 JOmega2D(const JAngle2D& dir,
93 const double phiMax,
94 const double grid) :
96 {
97 configure(dir, phiMax, grid);
98 }
99
100
101 /**
102 * Configure direction set.
103 *
104 * \param dir principal direction
105 * \param phiMax maximal angle [rad]
106 * \param grid angular spacing [rad]
107 */
108 void configure(const JAngle2D& dir,
109 const double phiMax,
110 const double grid)
111 {
112 clear();
113
114 // sanity checks
115
116 double phi_min = 0.0;
117 double phi_max = phiMax;
118
119 if (phi_max < 0.0) phi_max = 0.0;
120 if (phi_max > PI) phi_max = PI;
121
122 if (phi_max > phi_min) {
123
124 const double rad = phi_max - phi_min;
125 const double bin = rad / floor(rad/grid + 0.5); // angle step size
126
127 for (double phi = phi_min; phi < phi_max + 0.5*bin; phi += bin) {
128
129 if (phi < 0.5*bin) {
130 push_back(dir);
131 } else if (PI - phi < 0.5*bin) {
132 push_back(dir + PI);
133 } else {
134 push_back(dir + phi);
135 push_back(dir - phi);
136 }
137 }
138 }
139 }
140 };
141}
142
143#endif
Mathematical constants.
Data structure for angle in two dimensions.
Definition JAngle2D.hh:35
double getDot(const JAngle2D &angle) const
Get dot product.
Definition JAngle2D.hh:189
Direction set covering (part of) circle.
Definition JOmega2D.hh:62
JOmega2D(const JAngle2D &dir, const double phiMax, const double grid)
Constructor.
Definition JOmega2D.hh:92
void configure(const JAngle2D &dir, const double phiMax, const double grid)
Configure direction set.
Definition JOmega2D.hh:108
JOmega2D()
Default constructor.
Definition JOmega2D.hh:67
JOmega2D(const double grid)
Constructor.
Definition JOmega2D.hh:77
Auxiliary classes and methods for 2D geometrical objects and operations.
Definition JAngle2D.hh:19
static const double PI
Mathematical constants.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Base class for direction set.
Definition JOmega2D.hh:30
int find(const JAngle2D &dir) const
Get index of direction closest to given direction.
Definition JOmega2D.hh:37