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>
98 : fVect(p2 - p1)
99 { }
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 >
161 PositionVector3D<CoordSystem,Tag> operator() (const PositionVector3D <CoordSystem,Tag> & p) const {
162 return PositionVector3D<CoordSystem, Tag>(p.X() + fVect.X(), p.Y() + fVect.Y(), p.Z() + fVect.Z());
163 }
164 /**
165 Transformation operation
166 */
167 template <class CoordSystem, class Tag>
169 {
170 return operator()(v);
171 }
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 >
178 DisplacementVector3D<CoordSystem,Tag> operator() (const DisplacementVector3D <CoordSystem,Tag> & v) const {
179 return v;
180 }
181 /**
182 Transformation operation
183 */
184 template <class CoordSystem, class Tag>
186 {
187 return operator()(v);
188 }
189
190 /**
191 Transformation operation for points between different coordinate system tags
192 */
193 template<class CoordSystem, class Tag1, class Tag2 >
194 void Transform (const PositionVector3D <CoordSystem,Tag1> & p1, PositionVector3D <CoordSystem,Tag2> & p2 ) const {
195 PositionVector3D <CoordSystem,Tag2> tmp;
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>
216 {
217 return q;
218 }
219 /**
220 Transformation operation
221 */
222 template <class CoordSystem>
224 {
225 return operator()(q);
226 }
227
228 /**
229 Transformation on a 3D plane
230 */
231 Plane3D<T> operator()(const Plane3D<T> &plane) const
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 */
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
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
Definition TBuffer.h:399
winID h TVirtualViewer3D TVirtualGLPainter p
float * q
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:53
Vector Normal() const
Return normal vector to the plane as Cartesian DisplacementVector.
Definition Plane3D.h:158
Scalar HesseDistance() const
Return the Hesse Distance (distance from the origin) of the plane or the d coefficient expressed in n...
Definition Plane3D.h:164
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.
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
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.
const Int_t n
Definition legend1.C:16
Namespace for new Math classes and functions.
Impl::Translation3D< float > Translation3DF
Impl::Translation3D< double > Translation3D
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
TMarker m
Definition textangle.C:8