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_MathX_GenVectorX_Translation3D
17#define ROOT_MathX_GenVectorX_Translation3D 1
18
20
22
24
26
28
30
31#include <iostream>
32#include <type_traits>
33
34namespace ROOT {
35
36namespace ROOT_MATH_ARCH {
37
38namespace Impl {
39
40//____________________________________________________________________________________________________
41/**
42 Class describing a 3 dimensional translation. It can be combined (using the operator *)
43 with the ROOT::Math::Rotation3D classes and ROOT::Math::Transform3D to obtained combined
44 transformations and to operate on points and vectors.
45 Note that a the translation applied to a Vector object (DisplacementVector3D and LorentzVector classes)
46 performs a noop, i.e. it returns the same vector. A translation can be applied only to the Point objects
47 (PositionVector3D classes).
48
49 @ingroup GenVectorX
50
51 @see GenVectorX
52
53*/
54
55template <typename T = double>
57
58public:
59 typedef T Scalar;
60
62
63 /**
64 Default constructor ( zero translation )
65 */
67
68 /**
69 Construct given a pair of pointers or iterators defining the
70 beginning and end of an array of 3 Scalars representing the z,y,z of the translation vector
71 */
72 template <class IT>
73 Translation3D(IT begin, IT end)
74 {
75 fVect.SetCoordinates(begin, end);
76 }
77
78 /**
79 Construct from x,y,z values representing the translation
80 */
81 Translation3D(T dx, T dy, T dz) : fVect(Vector(dx, dy, dz)) {}
82
83 /**
84 Construct from any Displacement vector in ant tag and coordinate system
85 */
86 template <class CoordSystem, class Tag>
88 {
89 }
90
91 /**
92 Construct transformation from one coordinate system defined one point (the origin)
93 to a new coordinate system defined by other point (origin )
94 @param p1 point defining origin of original reference system
95 @param p2 point defining origin of transformed reference system
96
97 */
98 template <class CoordSystem, class Tag>
103
104 // use compiler generated copy ctor, copy assignment and dtor
105
106 // ======== Components ==============
107
108 /**
109 return a const reference to the underline vector representing the translation
110 */
111 const Vector &Vect() const { return fVect; }
112
113 /**
114 Set the 3 components given an iterator to the start of
115 the desired data, and another to the end (3 past start).
116 */
117 template <class IT>
118 void SetComponents(IT begin, IT end)
119 {
120 fVect.SetCoordinates(begin, end);
121 }
122
123 /**
124 Get the 3 components into data specified by an iterator begin
125 and another to the end of the desired data (12 past start).
126 */
127 template <class IT>
128 void GetComponents(IT begin, IT end) const
129 {
130 fVect.GetCoordinates(begin, end);
131 }
132
133 /**
134 Get the 3 matrix components into data specified by an iterator begin
135 */
136 template <class IT>
137 void GetComponents(IT begin) const
138 {
139 fVect.GetCoordinates(begin);
140 }
141
142 /**
143 Set the components from 3 scalars
144 */
145 void SetComponents(T dx, T dy, T dz) { fVect.SetCoordinates(dx, dy, dz); }
146
147 /**
148 Get the components into 3 scalars
149 */
150 void GetComponents(T &dx, T &dy, T &dz) const { fVect.GetCoordinates(dx, dy, dz); }
151
152 /**
153 Set the XYZ vector components from 3 scalars
154 */
155 void SetXYZ(T dx, T dy, T dz) { fVect.SetXYZ(dx, dy, dz); }
156
157 // operations on points and vectors
158
159 /**
160 Transformation operation for Position Vector in any coordinate system and default tag
161 */
162 template <class CoordSystem, class Tag>
167 /**
168 Transformation operation
169 */
170 template <class CoordSystem, class Tag>
175
176 /**
177 Transformation operation for Displacement Vector in any coordinate system and default tag
178 For the Displacement Vectors no translation apply so return the vector itself
179 */
180 template <class CoordSystem, class Tag>
185 /**
186 Transformation operation
187 */
188 template <class CoordSystem, class Tag>
193
194 /**
195 Transformation operation for points between different coordinate system tags
196 */
197 template <class CoordSystem, class Tag1, class Tag2>
199 {
201 tmp.SetXYZ(p1.X(), p1.Y(), p1.Z());
202 p2 = operator()(tmp);
203 }
204
205 /**
206 Transformation operation for Displacement Vector of different coordinate systems
207 */
208 template <class CoordSystem, class Tag1, class Tag2>
210 {
211 // just copy v1 in v2
212 v2.SetXYZ(v1.X(), v1.Y(), v1.Z());
213 }
214
215 /**
216 Transformation operation for a Lorentz Vector in any coordinate system
217 A LorentzVector contains a displacement vector so no translation applies as well
218 */
219 template <class CoordSystem>
224 /**
225 Transformation operation
226 */
227 template <class CoordSystem>
232
233 /**
234 Transformation on a 3D plane
235 */
236 Plane3D<T> operator()(const Plane3D<T> &plane) const
237 {
238 // transformations on a 3D plane
239 const Vector n = plane.Normal();
240 // take a point on the plane. Use origin projection on the plane
241 // ( -ad, -bd, -cd) if (a**2 + b**2 + c**2 ) = 1
242 const T d = plane.HesseDistance();
243 PositionVector3D<Cartesian3D<T>> p(-d * n.X(), -d * n.Y(), -d * n.Z());
244 return PLANE(operator()(n), operator()(p));
245 }
246
247 /**
248 multiply (combine) with another transformation in place
249 */
251 {
252 fVect += t.Vect();
253 return *this;
254 }
255
256 /**
257 multiply (combine) two transformations
258 */
260
261 /**
262 Invert the transformation in place
263 */
264 void Invert() { SetComponents(-fVect.X(), -fVect.Y(), -fVect.Z()); }
265
266 /**
267 Return the inverse of the transformation.
268 */
269 Translation3D<T> Inverse() const { return Translation3D<T>(-fVect.X(), -fVect.Y(), -fVect.Z()); }
270
271 /**
272 Equality/inequality operators
273 */
274 bool operator==(const Translation3D<T> &rhs) const
275 {
276 if (fVect != rhs.fVect)
277 return false;
278 return true;
279 }
280
281 bool operator!=(const Translation3D<T> &rhs) const { return !operator==(rhs); }
282
283private:
284 Vector fVect; // internal 3D vector representing the translation
285};
286
287// global functions
288#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
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 formatting 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#endif
302// need a function Transform = Translation * Rotation ???
303
304} // end namespace Impl
305
306// typedefs for double and float versions
309
310} // namespace ROOT_MATH_ARCH
311
312} // end namespace ROOT
313
314#endif /* ROOT_MathX_GenVectorX_Translation3D */
#define d(i)
Definition RSha256.hxx:102
#define X(type, name)
float * q
DefaultCoordinateSystemTag Default tag for identifying any coordinate system.
Class describing a generic displacement vector in 3 dimensions.
Class describing a geometrical plane in 3 dimensions.
Definition Plane3D.h:51
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
Vector Normal() const
Return normal vector to the plane as Cartesian DisplacementVector.
Definition Plane3D.h:156
Class describing a 3 dimensional translation.
DisplacementVector3D< Cartesian3D< T >, DefaultCoordinateSystemTag > Vector
LorentzVector< CoordSystem > operator*(const LorentzVector< CoordSystem > &q) const
Transformation operation.
bool operator!=(const Translation3D< T > &rhs) const
void SetComponents(T dx, T dy, T dz)
Set the components from 3 scalars.
LorentzVector< CoordSystem > operator()(const LorentzVector< CoordSystem > &q) const
Transformation operation for a Lorentz Vector in any coordinate system A LorentzVector contains a dis...
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...
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...
bool operator==(const Translation3D< T > &rhs) const
Equality/inequality operators.
Translation3D(IT begin, IT end)
Construct given a pair of pointers or iterators defining the beginning and end of an array of 3 Scala...
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 > operator*(const Translation3D< T > &t) const
multiply (combine) two transformations
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(const DisplacementVector3D< CoordSystem, Tag > &v)
Construct from any Displacement vector in ant tag and coordinate system.
Translation3D< T > & operator*=(const Translation3D< T > &t)
multiply (combine) with another transformation in place
void SetXYZ(T dx, T dy, T dz)
Set the XYZ vector components from 3 scalars.
void Invert()
Invert the transformation in place.
const Vector & Vect() const
return a const reference to the underline vector representing the translation
void GetComponents(IT begin) const
Get the 3 matrix components into data specified by an iterator begin.
Translation3D()
Default constructor ( zero translation ).
DisplacementVector3D< CoordSystem, Tag > operator*(const DisplacementVector3D< CoordSystem, Tag > &v) const
Transformation operation.
Translation3D(T dx, T dy, T dz)
Construct from x,y,z values representing the translation.
void Transform(const PositionVector3D< CoordSystem, Tag1 > &p1, PositionVector3D< CoordSystem, Tag2 > &p2) const
Transformation operation for points between different coordinate system tags.
void Transform(const DisplacementVector3D< CoordSystem, Tag1 > &v1, DisplacementVector3D< CoordSystem, Tag2 > &v2) const
Transformation operation for Displacement Vector of different coordinate systems.
Translation3D< T > Inverse() const
Return the inverse of the transformation.
DisplacementVector3D< CoordSystem, Tag > operator()(const DisplacementVector3D< CoordSystem, Tag > &v) const
Transformation operation for Displacement Vector in any coordinate system and default tag For the Dis...
PositionVector3D< CoordSystem, Tag > operator*(const PositionVector3D< CoordSystem, Tag > &v) const
Transformation operation.
void GetComponents(T &dx, T &dy, T &dz) const
Get the components into 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.
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...
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
const Int_t n
Definition legend1.C:16
std::ostream & operator<<(std::ostream &os, const Plane3D< T > &p)
Stream Output and Input.
Definition Plane3D.h:294
Impl::Translation3D< float > Translation3DF
Impl::Translation3D< double > Translation3D
TMarker m
Definition textangle.C:8