Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 performs 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 @sa Overview of the @ref GenVector "physics vector library"
49
50*/
51
52template <typename T = double>
54
55public:
56 typedef T Scalar;
57
59
60 /**
61 Default constructor ( zero translation )
62 */
64
65 /**
66 Construct given a pair of pointers or iterators defining the
67 beginning and end of an array of 3 Scalars representing the z,y,z of the translation vector
68 */
69 template<class IT>
70 Translation3D(IT begin, IT end)
71 {
72 fVect.SetCoordinates(begin,end);
73 }
74
75 /**
76 Construct from x,y,z values representing the translation
77 */
78 Translation3D(T dx, T dy, T dz) : fVect(Vector(dx, dy, dz)) {}
79
80 /**
81 Construct from any Displacement vector in ant tag and coordinate system
82 */
83 template<class CoordSystem, class Tag>
85 fVect(Vector(v.X(),v.Y(),v.Z()))
86 { }
87
88
89 /**
90 Construct transformation from one coordinate system defined one point (the origin)
91 to a new coordinate system defined by other point (origin )
92 @param p1 point defining origin of original reference system
93 @param p2 point defining origin of transformed reference system
94
95 */
96 template <class CoordSystem, class Tag>
100
101
102 // use compiler generated copy ctor, copy assignment and dtor
103
104
105 // ======== Components ==============
106
107 /**
108 return a const reference to the underline vector representing the translation
109 */
110 const Vector & Vect() const { return fVect; }
111
112 /**
113 Set the 3 components given an iterator to the start of
114 the desired data, and another to the end (3 past start).
115 */
116 template<class IT>
117 void SetComponents(IT begin, IT end) {
118 fVect.SetCoordinates(begin,end);
119 }
120
121 /**
122 Get the 3 components into data specified by an iterator begin
123 and another to the end of the desired data (12 past start).
124 */
125 template<class IT>
126 void GetComponents(IT begin, IT end) const {
127 fVect.GetCoordinates(begin,end);
128 }
129
130 /**
131 Get the 3 matrix components into data specified by an iterator begin
132 */
133 template<class IT>
134 void GetComponents(IT begin) const {
135 fVect.GetCoordinates(begin);
136 }
137
138
139 /**
140 Set the components from 3 scalars
141 */
142 void SetComponents(T dx, T dy, T dz) { fVect.SetCoordinates(dx, dy, dz); }
143
144 /**
145 Get the components into 3 scalars
146 */
147 void GetComponents(T &dx, T &dy, T &dz) const { fVect.GetCoordinates(dx, dy, dz); }
148
149 /**
150 Set the XYZ vector components from 3 scalars
151 */
152 void SetXYZ(T dx, T dy, T dz) { fVect.SetXYZ(dx, dy, dz); }
153
154 // operations on points and vectors
155
156
157 /**
158 Transformation operation for Position Vector in any coordinate system and default tag
159 */
160 template<class CoordSystem, class Tag >
164 /**
165 Transformation operation
166 */
167 template <class CoordSystem, class Tag>
172
173 /**
174 Transformation operation for Displacement Vector in any coordinate system and default tag
175 For the Displacement Vectors no translation apply so return the vector itself
176 */
177 template<class CoordSystem, class Tag >
181 /**
182 Transformation operation
183 */
184 template <class CoordSystem, class Tag>
189
190 /**
191 Transformation operation for points between different coordinate system tags
192 */
193 template<class CoordSystem, class Tag1, class Tag2 >
196 tmp.SetXYZ( p1.X(), p1.Y(), p1.Z() );
197 p2 = operator()(tmp);
198 }
199
200 /**
201 Transformation operation for Displacement Vector of different coordinate systems
202 */
203 template <class CoordSystem, class Tag1, class Tag2>
205 {
206 // just copy v1 in v2
207 v2.SetXYZ(v1.X(), v1.Y(), v1.Z());
208 }
209
210 /**
211 Transformation operation for a Lorentz Vector in any coordinate system
212 A LorentzVector contains a displacement vector so no translation applies as well
213 */
214 template <class CoordSystem>
219 /**
220 Transformation operation
221 */
222 template <class CoordSystem>
227
228 /**
229 Transformation on a 3D plane
230 */
232 {
233 // transformations on a 3D plane
234 const Vector n = plane.Normal();
235 // take a point on the plane. Use origin projection on the plane
236 // ( -ad, -bd, -cd) if (a**2 + b**2 + c**2 ) = 1
237 const T d = plane.HesseDistance();
238 PositionVector3D<Cartesian3D<T>> p(-d * n.X(), -d * n.Y(), -d * n.Z());
239 return PLANE(operator()(n), operator()(p));
240 }
241
242 /**
243 multiply (combine) with another transformation in place
244 */
246 {
247 fVect+= t.Vect();
248 return *this;
249 }
250
251 /**
252 multiply (combine) two transformations
253 */
254 Translation3D<T> operator*(const Translation3D<T> &t) const { return Translation3D<T>(fVect + t.Vect()); }
255
256 /**
257 Invert the transformation in place
258 */
259 void Invert() {
260 SetComponents( -fVect.X(), -fVect.Y(),-fVect.Z() );
261 }
262
263 /**
264 Return the inverse of the transformation.
265 */
266 Translation3D<T> Inverse() const { return Translation3D<T>(-fVect.X(), -fVect.Y(), -fVect.Z()); }
267
268 /**
269 Equality/inequality operators
270 */
271 bool operator==(const Translation3D<T> &rhs) const
272 {
273 if( fVect != rhs.fVect ) return false;
274 return true;
275 }
276
277 bool operator!=(const Translation3D<T> &rhs) const { return !operator==(rhs); }
278
279private:
280
281 Vector fVect; // internal 3D vector representing the translation
282
283};
284
285
286
287
288
289// global functions
290
291// TODO - I/O should be put in the manipulator form
292
293template <class T>
294std::ostream &operator<<(std::ostream &os, const Translation3D<T> &t)
295{
296 // TODO - this will need changing for machine-readable issues
297 // and even the human readable form needs formatting improvements
298
299 T m[3];
300 t.GetComponents(m, m + 3);
301 return os << "\n" << m[0] << " " << m[1] << " " << m[2] << "\n";
302}
303
304// need a function Transform = Translation * Rotation ???
305
306} // end namespace Impl
307
308// typedefs for double and float versions
311
312} // end namespace Math
313
314} // end namespace ROOT
315
316
317#endif /* ROOT_Math_GenVector_Translation3D */
#define d(i)
Definition RSha256.hxx:102
#define X(type, name)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
float * q
DefaultCoordinateSystemTag Default tag for identifying any coordinate system.
Class describing a 3 dimensional translation.
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.
Translation3D()
Default constructor ( zero translation )
constexpr Translation3D(const DisplacementVector3D< CoordSystem, Tag > &v)
Construct from any Displacement vector in ant tag and coordinate system.
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...
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
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...
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.
const Int_t n
Definition legend1.C:16
Namespace for new Math classes and functions.
std::ostream & operator<<(std::ostream &os, const Plane3D< T > &p)
Stream Output and Input.
Definition Plane3D.h:296
Impl::Translation3D< float > Translation3DF
Impl::Translation3D< double > Translation3D
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
TMarker m
Definition textangle.C:8