Belle II Software  release-05-02-19
Point2D.h
1 //-----------------------------------------------------------------------------
2 // $Id$
3 //-----------------------------------------------------------------------------
4 // Filename : TRGPoint2D.h
5 // Section : TRG
6 // Owner : Yoshihito Iwasaki
7 // Email : yoshihito.iwasaki@kek.jp
8 //-----------------------------------------------------------------------------
9 // Description : A class to represent a point in 2D.
10 //-----------------------------------------------------------------------------
11 // $Log$
12 //-----------------------------------------------------------------------------
13 
14 #ifndef TRGPoint2D_FLAG_
15 #define TRGPoint2D_FLAG_
16 
17 #include <cmath>
18 #include "CLHEP/Geometry/Point3D.h"
19 #include "CLHEP/Geometry/Vector3D.h"
20 
21 namespace Belle2 {
27  typedef HepGeom::Vector3D<double> Vector3D;
28 
29 // class CLHEP::Hep3Vector;
30 
32  class TRGPoint2D {
33 
34  public:
36  TRGPoint2D();
38  TRGPoint2D(double, double);
42  TRGPoint2D(const Vector3D&);
44  TRGPoint2D(const CLHEP::Hep3Vector&);
45 
47  virtual ~TRGPoint2D();
48 
49  public:// Selectors
51  double x(void) const;
53  double y(void) const;
55  double mag(void) const;
57  double mag2(void) const;
59  double phi(void) const;
60 
61  public:// Modifiers
63  double x(double);
65  double y(double);
66 
67  public:// Operators
69  double dot(const TRGPoint2D&) const;
71  double cross(const TRGPoint2D&) const;
73  TRGPoint2D unit(void) const;
75  TRGPoint2D operator + (const TRGPoint2D&) const;
77  TRGPoint2D operator - (const TRGPoint2D&) const;
79  TRGPoint2D operator - () const;
81  bool operator == (const TRGPoint2D&) const;
82 
83  private:
85  double _p[2];
86  };
87 
89  std::ostream&
90  operator << (std::ostream&, const TRGPoint2D&);
91 
92 //-----------------------------------------------------------------------------
93 
94  inline
95  double
96  TRGPoint2D::x(void) const
97  {
98  return _p[0];
99  }
100 
101  inline
102  double
103  TRGPoint2D::y(void) const
104  {
105  return _p[1];
106  }
107 
108  inline
109  double
110  TRGPoint2D::x(double a)
111  {
112  return _p[0] = a;
113  }
114 
115  inline
116  double
117  TRGPoint2D::y(double a)
118  {
119  return _p[1] = a;
120  }
121 
122  inline
123  double
124  TRGPoint2D::mag(void) const
125  {
126  return sqrt(_p[0] * _p[0] + _p[1] * _p[1]);
127  }
128 
129  inline
130  double
131  TRGPoint2D::mag2(void) const
132  {
133  return _p[0] * _p[0] + _p[1] * _p[1];
134  }
135 
136  inline
137  double
138  TRGPoint2D::phi(void) const
139  {
140  if (_p[0] == 0.0 && _p[1] == 0.0) return 0.;
141  double a = atan2(_p[1], _p[0]);
142  if (a > 0) return a;
143  return a + 2. * M_PI;
144  }
145 
146  inline
147  double
148  TRGPoint2D::dot(const TRGPoint2D& a) const
149  {
150  return _p[0] * a.x() + _p[1] * a.y();
151  }
152 
153  inline
154  double
156  {
157  return _p[0] * a.y() - a.x() * _p[1];
158  }
159 
160  inline
161  TRGPoint2D
163  {
164  return TRGPoint2D(_p[0] + a.x(), _p[1] + a.y());
165  }
166 
167  inline
168  TRGPoint2D
170  {
171  return TRGPoint2D(_p[0] - a.x(), _p[1] - a.y());
172  }
173 
174  inline
175  TRGPoint2D
177  {
178  return TRGPoint2D(- _p[0], - _p[1]);
179  }
180 
181  inline
182  bool
184  {
185  if (a.x() == _p[0] && a.y() == _p[1]) return true;
186  return false;
187  }
188 
189  inline
190  TRGPoint2D
191  TRGPoint2D::unit(void) const
192  {
193  double sum2 = _p[0] * _p[0] + _p[1] * _p[1];
194  if (sum2 == 0.) return TRGPoint2D(0., 0.);
195  double sum = sqrt(sum2);
196  return TRGPoint2D(_p[0] / sum, _p[1] / sum);
197  }
198 
200 } // namespace Belle2k
201 
202 #endif /* TRGPoint2D_FLAG_ */
Belle2::TRGPoint2D::mag2
double mag2(void) const
magnitude square of the point
Definition: Point2D.h:131
Belle2::Vector3D
HepGeom::Vector3D< double > Vector3D
3D Vector
Definition: Cell.h:35
Belle2::operator<<
std::ostream & operator<<(std::ostream &output, const IntervalOfValidity &iov)
Definition: IntervalOfValidity.cc:196
Belle2::TRGPoint2D
A class to represent a point in 2D.
Definition: Point2D.h:32
Belle2::TRGPoint2D::operator+
TRGPoint2D operator+(const TRGPoint2D &) const
Definition: Point2D.h:162
Belle2::TRGPoint2D::mag
double mag(void) const
magnitude of the point
Definition: Point2D.h:124
Belle2::TRGPoint2D::TRGPoint2D
TRGPoint2D()
Constructor.
Definition: Point2D.cc:22
Belle2::TRGPoint2D::y
double y(void) const
y of the point
Definition: Point2D.h:103
Belle2::TRGPoint2D::operator-
TRGPoint2D operator-() const
Definition: Point2D.h:176
Belle2::TRGPoint2D::x
double x(void) const
x of the point
Definition: Point2D.h:96
Belle2::TRGPoint2D::phi
double phi(void) const
phi of the point
Definition: Point2D.h:138
Belle2::TRGPoint2D::cross
double cross(const TRGPoint2D &) const
outer product
Definition: Point2D.h:155
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TRGPoint2D::~TRGPoint2D
virtual ~TRGPoint2D()
Destructor.
Definition: Point2D.cc:52
Belle2::TRGPoint2D::operator==
bool operator==(const TRGPoint2D &) const
equal operator
Definition: Point2D.h:183
Belle2::TRGPoint2D::_p
double _p[2]
vector
Definition: Point2D.h:85
Belle2::TRGPoint2D::unit
TRGPoint2D unit(void) const
unit vector
Definition: Point2D.h:191
HepGeom::Point3D< double >
Belle2::TRGPoint2D::dot
double dot(const TRGPoint2D &) const
inner product
Definition: Point2D.h:148