Logo ROOT   6.18/05
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
23
25
27
28#include <iostream>
29#include <type_traits>
30
31namespace ROOT {
32
33namespace Math {
34
35namespace 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
50template <typename T = double>
52
53public:
54 typedef T Scalar;
55
57
58 /**
59 Default constructor ( zero translation )
60 */
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 */
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
277private:
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
291template <class T>
292std::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 */
SVector< double, 2 > v
Definition: Dict.h:5
#define d(i)
Definition: RSha256.hxx:102
float * q
Definition: THbookFile.cxx:87
DefaultCoordinateSystemTag Default tag for identifying any coordinate system.
Class describing a generic displacement vector in 3 dimensions.
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
void GetCoordinates(Scalar &a, Scalar &b, Scalar &c) const
get internal data into 3 Scalar numbers
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
DisplacementVector3D< CoordSystem, Tag > & SetCoordinates(const Scalar src[])
Set internal data based on a C-style array of 3 Scalar numbers.
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...
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Class describing a geometrical plane in 3 dimensions.
Definition: Plane3D.h:51
Vector Normal() const
Return normal vector to the plane as Cartesian DisplacementVector.
Definition: Plane3D.h:156
Scalar HesseDistance() const
Return the Hesse Distance (distance from the origin) of the plane or the d coefficient expressed in n...
Definition: Plane3D.h:162
Class describing a 3 dimensional translation.
Definition: Translation3D.h:51
Translation3D< T > & operator*=(const Translation3D< T > &t)
multiply (combine) with another transformation in place
const Vector & Vect() const
return a const reference to the underline vector representing the translation
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...
Translation3D(T dx, T dy, T dz)
Construct from x,y,z values representing the translation.
Definition: Translation3D.h:76
Translation3D()
Default constructor ( zero translation )
Definition: Translation3D.h:61
Translation3D(const DisplacementVector3D< CoordSystem, Tag > &v)
Construct from any Displacement vector in ant tag and coordinate system.
Definition: Translation3D.h:82
void SetXYZ(T dx, T dy, T dz)
Set the XYZ vector components from 3 scalars.
Translation3D< T > Inverse() const
Return the inverse of the transformation.
void GetComponents(T &dx, T &dy, T &dz) const
Get the components into 3 scalars.
void Transform(const DisplacementVector3D< CoordSystem, Tag1 > &v1, DisplacementVector3D< CoordSystem, Tag2 > &v2) const
Transformation operation for Displacement Vector of different coordinate systems.
Translation3D(const PositionVector3D< CoordSystem, Tag > &p1, const PositionVector3D< CoordSystem, Tag > &p2)
Construct transformation from one coordinate system defined one point (the origin) to a new coordinat...
Definition: Translation3D.h:95
PositionVector3D< CoordSystem, Tag > operator*(const PositionVector3D< CoordSystem, Tag > &v) const
Transformation operation.
LorentzVector< CoordSystem > operator*(const LorentzVector< CoordSystem > &q) const
Transformation operation.
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...
void GetComponents(IT begin) const
Get the 3 matrix components into data specified by an iterator begin.
LorentzVector< CoordSystem > operator()(const LorentzVector< CoordSystem > &q) const
Transformation operation for a Lorentz Vector in any coordinate system A LorentzVector contains a dis...
bool operator==(const Translation3D< T > &rhs) const
Equality/inequality operators.
DisplacementVector3D< Cartesian3D< T >, DefaultCoordinateSystemTag > Vector
Definition: Translation3D.h:56
Plane3D< T > operator()(const Plane3D< T > &plane) const
Transformation on a 3D plane.
PositionVector3D< CoordSystem, Tag > operator()(const PositionVector3D< CoordSystem, Tag > &p) const
Transformation operation for Position Vector in any coordinate system and default tag.
Translation3D(IT begin, IT end)
Construct given a pair of pointers or iterators defining the beginning and end of an array of 3 Scala...
Definition: Translation3D.h:68
DisplacementVector3D< CoordSystem, Tag > operator*(const DisplacementVector3D< CoordSystem, Tag > &v) const
Transformation operation.
void Invert()
Invert the transformation in place.
Translation3D< T > operator*(const Translation3D< T > &t) const
multiply (combine) two transformations
void Transform(const PositionVector3D< CoordSystem, Tag1 > &p1, PositionVector3D< CoordSystem, Tag2 > &p2) const
Transformation operation for points between different coordinate system tags.
bool operator!=(const Translation3D< T > &rhs) const
void SetComponents(T dx, T dy, T dz)
Set the components from 3 scalars.
Class describing a generic position vector (point) in 3 dimensions.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
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...
const Int_t n
Definition: legend1.C:16
Namespace for new Math classes and functions.
double T(double x)
Definition: ChebyshevPol.h:34
std::ostream & operator<<(std::ostream &os, const Plane3D< T > &p)
Stream Output and Input.
Definition: Plane3D.h:292
Impl::Translation3D< float > Translation3DF
Impl::Translation3D< double > Translation3D
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
auto * m
Definition: textangle.C:8