Logo ROOT  
Reference Guide
Translation3D.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Authors: W. Brown, M. Fischler, L. Moneta 2005
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2005 , LCG ROOT MathLib Team *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Header file for class Translation3D
12 //
13 // Created by: Lorenzo Moneta October 21 2005
14 //
15 //
16 #ifndef ROOT_Math_GenVector_Translation3D
17 #define ROOT_Math_GenVector_Translation3D 1
18 
19 
21 
22 #include "Math/GenVector/Plane3D.h"
23 
25 
27 
28 #include <iostream>
29 #include <type_traits>
30 
31 namespace ROOT {
32 
33 namespace Math {
34 
35 namespace Impl {
36 
37 //____________________________________________________________________________________________________
38 /**
39  Class describing a 3 dimensional translation. It can be combined (using the operator *)
40  with the ROOT::Math::Rotation3D classes and ROOT::Math::Transform3D to obtained combined
41  transformations and to operate on points and vectors.
42  Note that a the translation applied to a Vector object (DisplacementVector3D and LorentzVector classes)
43  performes a noop, i.e. it returns the same vector. A translation can be applied only to the Point objects
44  (PositionVector3D classes).
45 
46  @ingroup GenVector
47 
48 */
49 
50 template <typename T = double>
51 class Translation3D {
52 
53 public:
54  typedef T Scalar;
55 
56  typedef DisplacementVector3D<Cartesian3D<T>, DefaultCoordinateSystemTag> Vector;
57 
58  /**
59  Default constructor ( zero translation )
60  */
61  Translation3D() {}
62 
63  /**
64  Construct given a pair of pointers or iterators defining the
65  beginning and end of an array of 3 Scalars representing the z,y,z of the translation vector
66  */
67  template<class IT>
68  Translation3D(IT begin, IT end)
69  {
70  fVect.SetCoordinates(begin,end);
71  }
72 
73  /**
74  Construct from x,y,z values representing the translation
75  */
76  Translation3D(T dx, T dy, T dz) : fVect(Vector(dx, dy, dz)) {}
77 
78  /**
79  Construct from any Displacement vector in ant tag and coordinate system
80  */
81  template<class CoordSystem, class Tag>
83  fVect(Vector(v.X(),v.Y(),v.Z()))
84  { }
85 
86 
87  /**
88  Construct transformation from one coordinate system defined one point (the origin)
89  to a new coordinate system defined by other point (origin )
90  @param p1 point defining origin of original reference system
91  @param p2 point defining origin of transformed reference system
92 
93  */
94  template <class CoordSystem, class Tag>
96  : fVect(p2 - p1)
97  { }
98 
99 
100  // use compiler generated copy ctor, copy assignmet and dtor
101 
102 
103  // ======== Components ==============
104 
105  /**
106  return a const reference to the underline vector representing the translation
107  */
108  const Vector & Vect() const { return fVect; }
109 
110  /**
111  Set the 3 components given an iterator to the start of
112  the desired data, and another to the end (3 past start).
113  */
114  template<class IT>
115  void SetComponents(IT begin, IT end) {
116  fVect.SetCoordinates(begin,end);
117  }
118 
119  /**
120  Get the 3 components into data specified by an iterator begin
121  and another to the end of the desired data (12 past start).
122  */
123  template<class IT>
124  void GetComponents(IT begin, IT end) const {
125  fVect.GetCoordinates(begin,end);
126  }
127 
128  /**
129  Get the 3 matrix components into data specified by an iterator begin
130  */
131  template<class IT>
132  void GetComponents(IT begin) const {
133  fVect.GetCoordinates(begin);
134  }
135 
136 
137  /**
138  Set the components from 3 scalars
139  */
140  void SetComponents(T dx, T dy, T dz) { fVect.SetCoordinates(dx, dy, dz); }
141 
142  /**
143  Get the components into 3 scalars
144  */
145  void GetComponents(T &dx, T &dy, T &dz) const { fVect.GetCoordinates(dx, dy, dz); }
146 
147  /**
148  Set the XYZ vector components from 3 scalars
149  */
150  void SetXYZ(T dx, T dy, T dz) { fVect.SetXYZ(dx, dy, dz); }
151 
152  // operations on points and vectors
153 
154 
155  /**
156  Transformation operation for Position Vector in any coordinate system and default tag
157  */
158  template<class CoordSystem, class Tag >
160  return PositionVector3D<CoordSystem, Tag>(p.X() + fVect.X(), p.Y() + fVect.Y(), p.Z() + fVect.Z());
161  }
162  /**
163  Transformation operation
164  */
165  template <class CoordSystem, class Tag>
167  {
168  return operator()(v);
169  }
170 
171  /**
172  Transformation operation for Displacement Vector in any coordinate system and default tag
173  For the Displacement Vectors no translation apply so return the vector itself
174  */
175  template<class CoordSystem, class Tag >
177  return v;
178  }
179  /**
180  Transformation operation
181  */
182  template <class CoordSystem, class Tag>
184  {
185  return operator()(v);
186  }
187 
188  /**
189  Transformation operation for points between different coordinate system tags
190  */
191  template<class CoordSystem, class Tag1, class Tag2 >
194  tmp.SetXYZ( p1.X(), p1.Y(), p1.Z() );
195  p2 = operator()(tmp);
196  }
197 
198  /**
199  Transformation operation for Displacement Vector of different coordinate systems
200  */
201  template <class CoordSystem, class Tag1, class Tag2>
203  {
204  // just copy v1 in v2
205  v2.SetXYZ(v1.X(), v1.Y(), v1.Z());
206  }
207 
208  /**
209  Transformation operation for a Lorentz Vector in any coordinate system
210  A LorentzVector contains a displacement vector so no translation applies as well
211  */
212  template <class CoordSystem>
214  {
215  return q;
216  }
217  /**
218  Transformation operation
219  */
220  template <class CoordSystem>
222  {
223  return operator()(q);
224  }
225 
226  /**
227  Transformation on a 3D plane
228  */
229  Plane3D<T> operator()(const Plane3D<T> &plane) const
230  {
231  // transformations on a 3D plane
232  const Vector n = plane.Normal();
233  // take a point on the plane. Use origin projection on the plane
234  // ( -ad, -bd, -cd) if (a**2 + b**2 + c**2 ) = 1
235  const T d = plane.HesseDistance();
236  PositionVector3D<Cartesian3D<T>> p(-d * n.X(), -d * n.Y(), -d * n.Z());
237  return PLANE(operator()(n), operator()(p));
238  }
239 
240  /**
241  multiply (combine) with another transformation in place
242  */
244  {
245  fVect+= t.Vect();
246  return *this;
247  }
248 
249  /**
250  multiply (combine) two transformations
251  */
252  Translation3D<T> operator*(const Translation3D<T> &t) const { return Translation3D<T>(fVect + t.Vect()); }
253 
254  /**
255  Invert the transformation in place
256  */
257  void Invert() {
258  SetComponents( -fVect.X(), -fVect.Y(),-fVect.Z() );
259  }
260 
261  /**
262  Return the inverse of the transformation.
263  */
264  Translation3D<T> Inverse() const { return Translation3D<T>(-fVect.X(), -fVect.Y(), -fVect.Z()); }
265 
266  /**
267  Equality/inequality operators
268  */
269  bool operator==(const Translation3D<T> &rhs) const
270  {
271  if( fVect != rhs.fVect ) return false;
272  return true;
273  }
274 
275  bool operator!=(const Translation3D<T> &rhs) const { return !operator==(rhs); }
276 
277 private:
278 
279  Vector fVect; // internal 3D vector representing the translation
280 
281 };
282 
283 
284 
285 
286 
287 // global functions
288 
289 // TODO - I/O should be put in the manipulator form
290 
291 template <class T>
292 std::ostream &operator<<(std::ostream &os, const Translation3D<T> &t)
293 {
294  // TODO - this will need changing for machine-readable issues
295  // and even the human readable form needs formatiing improvements
296 
297  T m[3];
298  t.GetComponents(m, m + 3);
299  return os << "\n" << m[0] << " " << m[1] << " " << m[2] << "\n";
300 }
301 
302 // need a function Transform = Translation * Rotation ???
303 
304 } // end namespace Impl
305 
306 // typedefs for double and float versions
309 
310 } // end namespace Math
311 
312 } // end namespace ROOT
313 
314 
315 #endif /* ROOT_Math_GenVector_Translation3D */
ROOT::Math::PositionVector3D::Y
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
Definition: PositionVector3D.h:280
ROOT::Math::PositionVector3D::SetXYZ
PositionVector3D< CoordSystem, Tag > & SetXYZ(Scalar a, Scalar b, Scalar c)
set the values of the vector from the cartesian components (x,y,z) (if the vector is held in polar or...
Definition: PositionVector3D.h:253
m
auto * m
Definition: textangle.C:8
n
const Int_t n
Definition: legend1.C:16
Plane3D.h
ROOT::Math::Impl::Plane3D::Normal
Vector Normal() const
Return normal vector to the plane as Cartesian DisplacementVector.
Definition: Plane3D.h:176
ROOT::Math::Impl::Plane3D
Class describing a geometrical plane in 3 dimensions.
Definition: Plane3D.h:66
ROOT::Math::Impl::Translation3D::operator*
PositionVector3D< CoordSystem, Tag > operator*(const PositionVector3D< CoordSystem, Tag > &v) const
Transformation operation.
Definition: Translation3D.h:186
ROOT::Math::Impl::Translation3D
Class describing a 3 dimensional translation.
Definition: Translation3D.h:66
ROOT::Math::PositionVector3D
Class describing a generic position vector (point) in 3 dimensions.
Definition: PositionVector3D.h:63
ROOT::Math::Impl::Translation3D::Translation3D
Translation3D()
Default constructor ( zero translation )
Definition: Translation3D.h:81
ROOT::Math::Impl::Translation3D::SetComponents
void SetComponents(IT begin, IT end)
Set the 3 components given an iterator to the start of the desired data, and another to the end (3 pa...
Definition: Translation3D.h:135
ROOT::Math::DisplacementVector3D::SetCoordinates
DisplacementVector3D< CoordSystem, Tag > & SetCoordinates(const Scalar src[])
Set internal data based on a C-style array of 3 Scalar numbers.
Definition: DisplacementVector3D.h:198
ROOT::Math::DisplacementVector3D::Y
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
Definition: DisplacementVector3D.h:287
v
@ v
Definition: rootcling_impl.cxx:3635
ROOT::Math::PositionVector3D::X
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Definition: PositionVector3D.h:275
ROOT::Math::Impl::Translation3D::Scalar
T Scalar
Definition: Translation3D.h:74
q
float * q
Definition: THbookFile.cxx:89
ROOT::Math::Impl::Translation3D::operator*=
Translation3D< T > & operator*=(const Translation3D< T > &t)
multiply (combine) with another transformation in place
Definition: Translation3D.h:263
ROOT::Math::Impl::Plane3D::HesseDistance
Scalar HesseDistance() const
Return the Hesse Distance (distance from the origin) of the plane or the d coefficient expressed in n...
Definition: Plane3D.h:182
ROOT::Math::DisplacementVector3D::GetCoordinates
void GetCoordinates(Scalar &a, Scalar &b, Scalar &c) const
get internal data into 3 Scalar numbers
Definition: DisplacementVector3D.h:222
ROOT::Math::Impl::Translation3D::operator!=
bool operator!=(const Translation3D< T > &rhs) const
Definition: Translation3D.h:295
PositionVector3Dfwd.h
ROOT::Math::Impl::Translation3D::Vector
DisplacementVector3D< Cartesian3D< T >, DefaultCoordinateSystemTag > Vector
Definition: Translation3D.h:76
ROOT::Math::Impl::operator<<
std::ostream & operator<<(std::ostream &os, const Plane3D< T > &p)
Stream Output and Input.
Definition: Plane3D.h:307
ROOT::Math::Impl::Translation3D::operator==
bool operator==(const Translation3D< T > &rhs) const
Equality/inequality operators.
Definition: Translation3D.h:289
ROOT::Math::Impl::Translation3D::Inverse
Translation3D< T > Inverse() const
Return the inverse of the transformation.
Definition: Translation3D.h:284
ROOT::Math::Impl::Translation3D::Invert
void Invert()
Invert the transformation in place.
Definition: Translation3D.h:277
ROOT::Math::Impl::Translation3D::GetComponents
void GetComponents(IT begin, IT end) const
Get the 3 components into data specified by an iterator begin and another to the end of the desired d...
Definition: Translation3D.h:144
ROOT::Math::DisplacementVector3D::X
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Definition: DisplacementVector3D.h:282
ROOT::Math::DisplacementVector3D::Z
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Definition: DisplacementVector3D.h:292
ROOT::Math::PositionVector3D::Z
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Definition: PositionVector3D.h:285
ROOT::Math::Impl::Translation3D::fVect
Vector fVect
Definition: Translation3D.h:299
DisplacementVector3D.h
v1
@ v1
Definition: rootcling_impl.cxx:3637
ROOT::Math::Translation3D
Impl::Translation3D< double > Translation3D
Definition: Translation3D.h:317
v2
@ v2
Definition: rootcling_impl.cxx:3638
ROOT::Math::Impl::Translation3D::Transform
void Transform(const PositionVector3D< CoordSystem, Tag1 > &p1, PositionVector3D< CoordSystem, Tag2 > &p2) const
Transformation operation for points between different coordinate system tags.
Definition: Translation3D.h:212
ROOT::Math::DisplacementVector3D::SetXYZ
DisplacementVector3D< CoordSystem, Tag > & SetXYZ(Scalar a, Scalar b, Scalar c)
set the values of the vector from the cartesian components (x,y,z) (if the vector is held in polar or...
Definition: DisplacementVector3D.h:260
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:52
ROOT::Math::DisplacementVector3D
Class describing a generic displacement vector in 3 dimensions.
Definition: DisplacementVector3D.h:67
d
#define d(i)
Definition: RSha256.hxx:120
ROOT::Math::Impl::Translation3D::SetXYZ
void SetXYZ(T dx, T dy, T dz)
Set the XYZ vector components from 3 scalars.
Definition: Translation3D.h:170
ROOT::Math::Impl::Translation3D::operator()
PositionVector3D< CoordSystem, Tag > operator()(const PositionVector3D< CoordSystem, Tag > &p) const
Transformation operation for Position Vector in any coordinate system and default tag.
Definition: Translation3D.h:179
ROOT::Math::Impl::Translation3D::Vect
const Vector & Vect() const
return a const reference to the underline vector representing the translation
Definition: Translation3D.h:128
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Math::Translation3DF
Impl::Translation3D< float > Translation3DF
Definition: Translation3D.h:318
Math
ROOT::Math::LorentzVector
Definition: LorentzVector.h:70
LorentzVectorfwd.h