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