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