Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Point3D.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id:$
3 // ---------------------------------------------------------------------------
4 //
5 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
6 //
7 // History:
8 // 09.09.96 E.Chernyaev - initial version
9 // 12.06.01 E.Chernyaev - CLHEP-1.7: introduction of BasicVector3D to decouple
10 // the functionality from CLHEP::Hep3Vector
11 // 01.04.03 E.Chernyaev - CLHEP-1.9: template version
12 //
13 
14 #ifndef HEP_POINT3D_H
15 #define HEP_POINT3D_H
16 
17 #include <iosfwd>
20 
21 namespace HepGeom {
22 
23  class Transform3D;
24 
25  /**
26  * Geometrical 3D Point.
27  * This is just a declaration of the class needed to define
28  * specializations Point3D<float> and Point3D<double>.
29  *
30  * @ingroup geometry
31  * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
32  */
33  template<class T>
34  class Point3D : public BasicVector3D<T> {};
35 
36  /**
37  * Geometrical 3D Point with components of float type.
38  *
39  * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
40  * @ingroup geometry
41  */
42  template<>
43  class Point3D<float> : public BasicVector3D<float> {
44  public:
45  /**
46  * Default constructor. */
47  Point3D() {}
48 
49  /**
50  * Constructor from three numbers. */
51  Point3D(float x1, float y1, float z1) : BasicVector3D<float>(x1,y1,z1) {}
52 
53  /**
54  * Constructor from array of floats. */
55  explicit Point3D(const float * a)
56  : BasicVector3D<float>(a[0],a[1],a[2]) {}
57 
58  /**
59  * Copy constructor. */
60  Point3D(const Point3D<float> & v) : BasicVector3D<float>(v) {}
61 
62  /**
63  * Constructor from BasicVector3D<float>. */
64  Point3D(const BasicVector3D<float> & v) : BasicVector3D<float>(v) {}
65 
66  /**
67  * Destructor. */
68  ~Point3D() {}
69 
70  /**
71  * Assignment. */
73  set(v.x(),v.y(),v.z()); return *this;
74  }
75 
76  /**
77  * Assignment from BasicVector3D<float>. */
79  set(v.x(),v.y(),v.z()); return *this;
80  }
81 
82  /**
83  * Returns distance to the origin squared. */
84  float distance2() const { return mag2(); }
85 
86  /**
87  * Returns distance to the point squared. */
88  float distance2(const Point3D<float> & p) const {
89  float dx = p.x()-x(), dy = p.y()-y(), dz = p.z()-z();
90  return dx*dx + dy*dy + dz*dz;
91  }
92 
93  /**
94  * Returns distance to the origin. */
95  float distance() const { return std::sqrt(distance2()); }
96 
97  /**
98  * Returns distance to the point. */
99  float distance(const Point3D<float> & p) const {
100  return std::sqrt(distance2(p));
101  }
102 
103  /**
104  * Transformation by Transform3D. */
105  Point3D<float> & transform(const Transform3D & m);
106  };
107 
108  /**
109  * Transformation of Point3D<float> by Transform3D.
110  * @relates Point3D
111  */
112  Point3D<float>
113  operator*(const Transform3D & m, const Point3D<float> & p);
114 
115  /**
116  * Geometrical 3D Point with components of double type.
117  *
118  * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
119  * @ingroup geometry
120  */
121  template<>
122  class Point3D<double> : public BasicVector3D<double> {
123  public:
124  /**
125  * Default constructor. */
126  Point3D() {}
127 
128  /**
129  * Constructor from three numbers. */
130  Point3D(double x1, double y1, double z1) : BasicVector3D<double>(x1,y1,z1) {}
131 
132  /**
133  * Constructor from array of floats. */
134  explicit Point3D(const float * a)
135  : BasicVector3D<double>(a[0],a[1],a[2]) {}
136 
137  /**
138  * Constructor from array of doubles. */
139  explicit Point3D(const double * a)
140  : BasicVector3D<double>(a[0],a[1],a[2]) {}
141 
142  /**
143  * Copy constructor. */
144  Point3D(const Point3D<double> & v) : BasicVector3D<double>(v) {}
145 
146  /**
147  * Constructor from BasicVector3D<float>. */
148  Point3D(const BasicVector3D<float> & v) : BasicVector3D<double>(v) {}
149 
150  /**
151  * Constructor from BasicVector3D<double>. */
152  Point3D(const BasicVector3D<double> & v) : BasicVector3D<double>(v) {}
153 
154  /**
155  * Destructor. */
156  ~Point3D() {}
157 
158  /**
159  * Constructor from CLHEP::Hep3Vector.
160  * This constructor is needed only for backward compatibility and
161  * in principle should be absent.
162  */
164  : BasicVector3D<double>(v.x(),v.y(),v.z()) {}
165 
166  /**
167  * Conversion (cast) to CLHEP::Hep3Vector.
168  * This operator is needed only for backward compatibility and
169  * in principle should not exit.
170  */
171  operator CLHEP::Hep3Vector () const { return CLHEP::Hep3Vector(x(),y(),z()); }
172 
173  /**
174  * Assignment. */
176  set(v.x(),v.y(),v.z()); return *this;
177  }
178 
179  /**
180  * Assignment from BasicVector3D<float>. */
182  set(v.x(),v.y(),v.z()); return *this;
183  }
184 
185  /**
186  * Assignment from BasicVector3D<double>. */
188  set(v.x(),v.y(),v.z()); return *this;
189  }
190 
191  /**
192  * Returns distance to the origin squared. */
193  double distance2() const { return mag2(); }
194 
195  /**
196  * Returns distance to the point squared. */
197  double distance2(const Point3D<double> & p) const {
198  double dx = p.x()-x(), dy = p.y()-y(), dz = p.z()-z();
199  return dx*dx + dy*dy + dz*dz;
200  }
201 
202  /**
203  * Returns distance to the origin. */
204  double distance() const { return std::sqrt(distance2()); }
205 
206  /**
207  * Returns distance to the point. */
208  double distance(const Point3D<double> & p) const {
209  return std::sqrt(distance2(p));
210  }
211 
212  /**
213  * Transformation by Transform3D. */
214  Point3D<double> & transform(const Transform3D & m);
215  };
216 
217  /**
218  * Transformation of Point3D<double> by Transform3D.
219  * @relates Point3D
220  */
221  Point3D<double>
222  operator*(const Transform3D & m, const Point3D<double> & p);
223 
224 } /* namespace HepGeom */
225 
226 #endif /* HEP_POINT3D_H */
float distance2(const Point3D< float > &p) const
Definition: Point3D.h:88
Point3D(double x1, double y1, double z1)
Definition: Point3D.h:130
void set(T x1, T y1, T z1)
float distance2() const
Definition: Point3D.h:84
Point3D(const double *a)
Definition: Point3D.h:139
double distance2() const
Definition: Point3D.h:193
float distance(const Point3D< float > &p) const
Definition: Point3D.h:99
const char * p
Definition: xmltok.h:285
Point3D< float > & operator=(const Point3D< float > &v)
Definition: Point3D.h:72
double distance2(const Point3D< double > &p) const
Definition: Point3D.h:197
Point3D(const BasicVector3D< float > &v)
Definition: Point3D.h:148
double distance(const Point3D< double > &p) const
Definition: Point3D.h:208
Point3D< float > & operator=(const BasicVector3D< float > &v)
Definition: Point3D.h:78
Point3D(const BasicVector3D< double > &v)
Definition: Point3D.h:152
Point3D(const float *a)
Definition: Point3D.h:55
Point3D(const float *a)
Definition: Point3D.h:134
Point3D(float x1, float y1, float z1)
Definition: Point3D.h:51
Point3D< double > & operator=(const BasicVector3D< double > &v)
Definition: Point3D.h:187
Point3D(const BasicVector3D< float > &v)
Definition: Point3D.h:64
Point3D< double > & operator=(const BasicVector3D< float > &v)
Definition: Point3D.h:181
Point3D(const Point3D< float > &v)
Definition: Point3D.h:60
Point3D< double > & operator=(const Point3D< double > &v)
Definition: Point3D.h:175
double distance() const
Definition: Point3D.h:204
Normal3D< float > operator*(const Transform3D &m, const Normal3D< float > &v)
Definition: Normal3D.cc:24
Point3D(const Point3D< double > &v)
Definition: Point3D.h:144
Point3D(const CLHEP::Hep3Vector &v)
Definition: Point3D.h:163
float distance() const
Definition: Point3D.h:95