Logo ROOT   6.08/07
Reference Guide
Transform3D.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 Transform3D
12 //
13 // Created by: Lorenzo Moneta October 21 2005
14 //
15 //
16 #ifndef ROOT_Math_GenVector_Transform3D
17 #define ROOT_Math_GenVector_Transform3D 1
18 
19 
20 
21 #ifndef ROOT_Math_GenVector_DisplacementVector3D
23 #endif
24 
25 #ifndef ROOT_Math_GenVector_PositionVector3D
27 #endif
28 
29 #ifndef ROOT_Math_GenVector_Rotation3D
31 #endif
32 
33 #ifndef ROOT_Math_GenVector_Translation3D
35 #endif
36 
37 
45 
46 #include <iostream>
47 
48 //#include "Math/Vector3Dfwd.h"
49 
50 
51 
52 namespace ROOT {
53 
54 namespace Math {
55 
56 
57  class Plane3D;
58 
59 
60 //_________________________________________________________________________________________
61 /**
62  Basic 3D Transformation class describing a rotation and then a translation
63  The internal data are a 3D rotation data (represented as a 3x3 matrix) and a 3D vector data.
64  They are represented and held in this class like a 3x4 matrix (a simple array of 12 numbers).
65 
66  The class can be constructed from any 3D rotation object
67  (ROOT::Math::Rotation3D, ROOT::Math::AxisAngle, ROOT::Math::Quaternion, etc...) and/or
68  a 3D Vector (ROOT::Math::DislacementVector3D or via ROOT::Math::Translation ) representing a Translation.
69  The Transformation is defined by applying first the rotation and then the translation.
70  A transformation defined by applying first a translation and then a rotation is equivalent to the
71  transformation obtained applying first the rotation and then a translation equivalent to the rotated vector.
72  The operator * can be used to obtain directly such transformations, in addition to combine various
73  transformations.
74  Keep in mind that the operator * (like in the case of rotations ) is not commutative.
75  The operator * is used (in addition to operator() ) to apply a transformations on the vector
76  (DisplacementVector3D and LorentzVector classes) and point (PositionVector3D) classes.
77  In the case of Vector objects the transformation only rotates them and does not translate them.
78  Only Point objects are able to be both rotated and translated.
79 
80 
81  @ingroup GenVector
82 
83 */
84 
85 class Transform3D {
86 
87 
88 public:
89 
92 
93 
95  kXX = 0, kXY = 1, kXZ = 2, kDX = 3,
96  kYX = 4, kYY = 5, kYZ = 6, kDY = 7,
97  kZX = 8, kZY = 9, kZZ =10, kDZ = 11
98  };
99 
100 
101 
102  /**
103  Default constructor (identy rotation) + zero translation
104  */
106  {
107  SetIdentity();
108  }
109 
110  /**
111  Construct given a pair of pointers or iterators defining the
112  beginning and end of an array of 12 Scalars
113  */
114  template<class IT>
115  Transform3D(IT begin, IT end)
116  {
117  SetComponents(begin,end);
118  }
119 
120  /**
121  Construct from a rotation and then a translation described by a Vector
122  */
123  Transform3D( const Rotation3D & r, const Vector & v)
124  {
125  AssignFrom( r, v );
126  }
127  /**
128  Construct from a rotation and then a translation described by a Translation3D class
129  */
130  Transform3D( const Rotation3D & r, const Translation3D & t)
131  {
132  AssignFrom( r, t.Vect() );
133  }
134 
135  /**
136  Construct from a rotation (any rotation object) and then a translation
137  (represented by any DisplacementVector)
138  The requirements on the rotation and vector objects are that they can be transformed in a
139  Rotation3D class and in a Cartesian3D Vector
140  */
141  template <class ARotation, class CoordSystem, class Tag>
143  {
144  AssignFrom( Rotation3D(r), Vector (v.X(),v.Y(),v.Z()) );
145  }
146 
147  /**
148  Construct from a rotation (any rotation object) and then a translation
149  represented by a Translation3D class
150  The requirements on the rotation is that it can be transformed in a
151  Rotation3D class
152  */
153  template <class ARotation>
154  Transform3D( const ARotation & r, const Translation3D & t)
155  {
156  AssignFrom( Rotation3D(r), t.Vect() );
157  }
158 
159 
160 #ifdef OLD_VERSION
161  /**
162  Construct from a translation and then a rotation (inverse assignment)
163  */
164  Transform3D( const Vector & v, const Rotation3D & r)
165  {
166  // is equivalent from having first the rotation and then the translation vector rotated
167  AssignFrom( r, r(v) );
168  }
169 #endif
170 
171  /**
172  Construct from a 3D Rotation only with zero translation
173  */
174  explicit Transform3D( const Rotation3D & r) {
175  AssignFrom(r);
176  }
177 
178  // convenience methods for constructing a Transform3D from all the 3D rotations classes
179  // (cannot use templates for conflict with LA)
180 
181  explicit Transform3D( const AxisAngle & r) {
183  }
184  explicit Transform3D( const EulerAngles & r) {
186  }
187  explicit Transform3D( const Quaternion & r) {
189  }
190  explicit Transform3D( const RotationZYX & r) {
192  }
193 
194  // Constructors from axial rotations
195  // TO DO: implement direct methods for axial rotations without going through Rotation3D
196  explicit Transform3D( const RotationX & r) {
198  }
199  explicit Transform3D( const RotationY & r) {
201  }
202  explicit Transform3D( const RotationZ & r) {
204  }
205 
206  /**
207  Construct from a translation only, represented by any DisplacementVector3D
208  and with an identity rotation
209  */
210  template<class CoordSystem, class Tag>
212  AssignFrom(Vector(v.X(),v.Y(),v.Z()));
213  }
214  /**
215  Construct from a translation only, represented by a Cartesian 3D Vector,
216  and with an identity rotation
217  */
218  explicit Transform3D( const Vector & v) {
219  AssignFrom(v);
220  }
221  /**
222  Construct from a translation only, represented by a Translation3D class
223  and with an identity rotation
224  */
225  explicit Transform3D( const Translation3D & t) {
226  AssignFrom(t.Vect());
227  }
228 
229 
230 
231  //#if !defined(__MAKECINT__) && !defined(G__DICTIONARY) // this is ambigous with double * , double *
232 
233 
234 #ifdef OLD_VERSION
235  /**
236  Construct from a translation (using any type of DisplacementVector )
237  and then a rotation (any rotation object).
238  Requirement on the rotation and vector objects are that they can be transformed in a
239  Rotation3D class and in a Vector
240  */
241  template <class ARotation, class CoordSystem, class Tag>
242  Transform3D(const DisplacementVector3D<CoordSystem,Tag> & v , const ARotation & r)
243  {
244  // is equivalent from having first the rotation and then the translation vector rotated
245  Rotation3D r3d(r);
246  AssignFrom( r3d, r3d( Vector(v.X(),v.Y(),v.Z()) ) );
247  }
248 #endif
249 
250 
251  /**
252  Construct transformation from one coordinate system defined by three
253  points (origin + two axis) to
254  a new coordinate system defined by other three points (origin + axis)
255  @param fr0 point defining origin of original reference system
256  @param fr1 point defining first axis of original reference system
257  @param fr2 point defining second axis of original reference system
258  @param to0 point defining origin of transformed reference system
259  @param to1 point defining first axis transformed reference system
260  @param to2 point defining second axis transformed reference system
261 
262  */
264  (const Point & fr0, const Point & fr1, const Point & fr2,
265  const Point & to0, const Point & to1, const Point & to2 );
266 
267 
268  // use compiler generated copy ctor, copy assignmet and dtor
269 
270  /**
271  Construct from a linear algebra matrix of size at least 3x4,
272  which must support operator()(i,j) to obtain elements (0,0) thru (2,3).
273  The 3x3 sub-block is assumed to be the rotation part and the translations vector
274  are described by the 4-th column
275  */
276  template<class ForeignMatrix>
277  explicit Transform3D(const ForeignMatrix & m) {
278  SetComponents(m);
279  }
280 
281  /**
282  Raw constructor from 12 Scalar components
283  */
284  Transform3D(double xx, double xy, double xz, double dx,
285  double yx, double yy, double yz, double dy,
286  double zx, double zy, double zz, double dz)
287  {
288  SetComponents (xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz);
289  }
290 
291 
292  /**
293  Construct from a linear algebra matrix of size at least 3x4,
294  which must support operator()(i,j) to obtain elements (0,0) thru (2,3).
295  The 3x3 sub-block is assumed to be the rotation part and the translations vector
296  are described by the 4-th column
297  */
298  template<class ForeignMatrix>
299  Transform3D & operator= (const ForeignMatrix & m) {
300  SetComponents(m);
301  return *this;
302  }
303 
304 
305  // ======== Components ==============
306 
307 
308  /**
309  Set the 12 matrix components given an iterator to the start of
310  the desired data, and another to the end (12 past start).
311  */
312  template<class IT>
313 #ifndef NDEBUG
314  void SetComponents(IT begin, IT end) {
315 #else
316  void SetComponents(IT begin, IT ) {
317 #endif
318  for (int i = 0; i <12; ++i) {
319  fM[i] = *begin;
320  ++begin;
321  }
322  assert (end==begin);
323  }
324 
325  /**
326  Get the 12 matrix components into data specified by an iterator begin
327  and another to the end of the desired data (12 past start).
328  */
329  template<class IT>
330 #ifndef NDEBUG
331  void GetComponents(IT begin, IT end) const {
332 #else
333  void GetComponents(IT begin, IT ) const {
334 #endif
335  for (int i = 0; i <12; ++i) {
336  *begin = fM[i];
337  ++begin;
338  }
339  assert (end==begin);
340  }
341 
342  /**
343  Get the 12 matrix components into data specified by an iterator begin
344  */
345  template<class IT>
346  void GetComponents(IT begin) const {
347  std::copy ( fM, fM+12, begin );
348  }
349 
350  /**
351  Set components from a linear algebra matrix of size at least 3x4,
352  which must support operator()(i,j) to obtain elements (0,0) thru (2,3).
353  The 3x3 sub-block is assumed to be the rotation part and the translations vector
354  are described by the 4-th column
355  */
356  template<class ForeignMatrix>
357  void
358  SetTransformMatrix (const ForeignMatrix & m) {
359  fM[kXX]=m(0,0); fM[kXY]=m(0,1); fM[kXZ]=m(0,2); fM[kDX]=m(0,3);
360  fM[kYX]=m(1,0); fM[kYY]=m(1,1); fM[kYZ]=m(1,2); fM[kDY]=m(1,3);
361  fM[kZX]=m(2,0); fM[kZY]=m(2,1); fM[kZZ]=m(2,2); fM[kDZ]=m(2,3);
362  }
363 
364  /**
365  Get components into a linear algebra matrix of size at least 3x4,
366  which must support operator()(i,j) for write access to elements
367  (0,0) thru (2,3).
368  */
369  template<class ForeignMatrix>
370  void
371  GetTransformMatrix (ForeignMatrix & m) const {
372  m(0,0)=fM[kXX]; m(0,1)=fM[kXY]; m(0,2)=fM[kXZ]; m(0,3)=fM[kDX];
373  m(1,0)=fM[kYX]; m(1,1)=fM[kYY]; m(1,2)=fM[kYZ]; m(1,3)=fM[kDY];
374  m(2,0)=fM[kZX]; m(2,1)=fM[kZY]; m(2,2)=fM[kZZ]; m(2,3)=fM[kDZ];
375  }
376 
377 
378  /**
379  Set the components from 12 scalars
380  */
381  void
382  SetComponents (double xx, double xy, double xz, double dx,
383  double yx, double yy, double yz, double dy,
384  double zx, double zy, double zz, double dz) {
385  fM[kXX]=xx; fM[kXY]=xy; fM[kXZ]=xz; fM[kDX]=dx;
386  fM[kYX]=yx; fM[kYY]=yy; fM[kYZ]=yz; fM[kDY]=dy;
387  fM[kZX]=zx; fM[kZY]=zy; fM[kZZ]=zz; fM[kDZ]=dz;
388  }
389 
390  /**
391  Get the components into 12 scalars
392  */
393  void
394  GetComponents (double &xx, double &xy, double &xz, double &dx,
395  double &yx, double &yy, double &yz, double &dy,
396  double &zx, double &zy, double &zz, double &dz) const {
397  xx=fM[kXX]; xy=fM[kXY]; xz=fM[kXZ]; dx=fM[kDX];
398  yx=fM[kYX]; yy=fM[kYY]; yz=fM[kYZ]; dy=fM[kDY];
399  zx=fM[kZX]; zy=fM[kZY]; zz=fM[kZZ]; dz=fM[kDZ];
400  }
401 
402 
403  /**
404  Get the rotation and translation vector representing the 3D transformation
405  in any rotation and any vector (the Translation class could also be used)
406  */
407  template<class AnyRotation, class V>
408  void GetDecomposition(AnyRotation &r, V &v) const {
409  GetRotation(r);
410  GetTranslation(v);
411  }
412 
413 
414  /**
415  Get the rotation and translation vector representing the 3D transformation
416  */
417  void GetDecomposition(Rotation3D &r, Vector &v) const {
418  GetRotation(r);
419  GetTranslation(v);
420  }
421 
422  /**
423  Get the 3D rotation representing the 3D transformation
424  */
426  return Rotation3D( fM[kXX], fM[kXY], fM[kXZ],
427  fM[kYX], fM[kYY], fM[kYZ],
428  fM[kZX], fM[kZY], fM[kZZ] );
429  }
430 
431  /**
432  Get the rotation representing the 3D transformation
433  */
434  template <class AnyRotation>
435  AnyRotation Rotation() const {
436  return AnyRotation(Rotation3D(fM[kXX], fM[kXY], fM[kXZ],
437  fM[kYX], fM[kYY], fM[kYZ],
438  fM[kZX], fM[kZY], fM[kZZ] ) );
439  }
440 
441  /**
442  Get the rotation (any type) representing the 3D transformation
443  */
444  template <class AnyRotation>
445  void GetRotation(AnyRotation &r) const {
446  r = Rotation();
447  }
448 
449  /**
450  Get the translation representing the 3D transformation in a Cartesian vector
451  */
453  return Translation3D( fM[kDX], fM[kDY], fM[kDZ] );
454  }
455 
456  /**
457  Get the translation representing the 3D transformation in any vector
458  which implements the SetXYZ method
459  */
460  template <class AnyVector>
461  void GetTranslation(AnyVector &v) const {
462  v.SetXYZ(fM[kDX], fM[kDY], fM[kDZ]);
463  }
464 
465 
466 
467  // operations on points and vectors
468 
469  /**
470  Transformation operation for Position Vector in Cartesian coordinate
471  For a Position Vector first a rotation and then a translation is applied
472  */
473  Point operator() (const Point & p) const {
474  return Point ( fM[kXX]*p.X() + fM[kXY]*p.Y() + fM[kXZ]*p.Z() + fM[kDX],
475  fM[kYX]*p.X() + fM[kYY]*p.Y() + fM[kYZ]*p.Z() + fM[kDY],
476  fM[kZX]*p.X() + fM[kZY]*p.Y() + fM[kZZ]*p.Z() + fM[kDZ] );
477  }
478 
479 
480  /**
481  Transformation operation for Displacement Vectors in Cartesian coordinate
482  For the Displacement Vectors only the rotation applies - no translations
483  */
484  Vector operator() (const Vector & v) const {
485  return Vector( fM[kXX]*v.X() + fM[kXY]*v.Y() + fM[kXZ]*v.Z() ,
486  fM[kYX]*v.X() + fM[kYY]*v.Y() + fM[kYZ]*v.Z() ,
487  fM[kZX]*v.X() + fM[kZY]*v.Y() + fM[kZZ]*v.Z() );
488  }
489 
490 
491  /**
492  Transformation operation for Position Vector in any coordinate system
493  */
494  template<class CoordSystem >
496  Point xyzNew = operator() ( Point(p) );
497  return PositionVector3D<CoordSystem> (xyzNew);
498  }
499 
500  /**
501  Transformation operation for Displacement Vector in any coordinate system
502  */
503  template<class CoordSystem >
505  Vector xyzNew = operator() ( Vector(v) );
506  return DisplacementVector3D<CoordSystem> (xyzNew);
507  }
508 
509  /**
510  Transformation operation for points between different coordinate system tags
511  */
512  template<class CoordSystem, class Tag1, class Tag2 >
514  Point xyzNew = operator() ( Point(p1.X(), p1.Y(), p1.Z()) );
515  p2.SetXYZ( xyzNew.X(), xyzNew.Y(), xyzNew.Z() );
516  }
517 
518 
519  /**
520  Transformation operation for Displacement Vector of different coordinate systems
521  */
522  template<class CoordSystem, class Tag1, class Tag2 >
524  Vector xyzNew = operator() ( Vector(v1.X(), v1.Y(), v1.Z() ) );
525  v2.SetXYZ( xyzNew.X(), xyzNew.Y(), xyzNew.Z() );
526  }
527 
528  /**
529  Transformation operation for a Lorentz Vector in any coordinate system
530  */
531  template <class CoordSystem >
533  Vector xyzNew = operator() ( Vector(q.Vect() ) );
534  return LorentzVector<CoordSystem> (xyzNew.X(), xyzNew.Y(), xyzNew.Z(), q.E() );
535  }
536 
537  /**
538  Transformation on a 3D plane
539  */
540  Plane3D operator() (const Plane3D & plane) const;
541 
542 
543  // skip transformation for arbitrary vectors - not really defined if point or displacement vectors
544 
545  // same but with operator *
546  /**
547  Transformation operation for Vectors. Apply same rules as operator()
548  depending on type of vector.
549  Will work only for DisplacementVector3D, PositionVector3D and LorentzVector
550  */
551  template<class AVector >
552  AVector operator * (const AVector & v) const {
553  return operator() (v);
554  }
555 
556 
557 
558  /**
559  multiply (combine) with another transformation in place
560  */
561  inline Transform3D & operator *= (const Transform3D & t);
562 
563  /**
564  multiply (combine) two transformations
565  */
566  inline Transform3D operator * (const Transform3D & t) const;
567 
568  /**
569  Invert the transformation in place
570  */
571  void Invert();
572 
573  /**
574  Return the inverse of the transformation.
575  */
576  Transform3D Inverse() const {
577  Transform3D t(*this);
578  t.Invert();
579  return t;
580  }
581 
582 
583  /**
584  Equality operator. Check equality for each element
585  To do: use double tolerance
586  */
587  bool operator == (const Transform3D & rhs) const {
588  if( fM[0] != rhs.fM[0] ) return false;
589  if( fM[1] != rhs.fM[1] ) return false;
590  if( fM[2] != rhs.fM[2] ) return false;
591  if( fM[3] != rhs.fM[3] ) return false;
592  if( fM[4] != rhs.fM[4] ) return false;
593  if( fM[5] != rhs.fM[5] ) return false;
594  if( fM[6] != rhs.fM[6] ) return false;
595  if( fM[7] != rhs.fM[7] ) return false;
596  if( fM[8] != rhs.fM[8] ) return false;
597  if( fM[9] != rhs.fM[9] ) return false;
598  if( fM[10]!= rhs.fM[10] ) return false;
599  if( fM[11]!= rhs.fM[11] ) return false;
600  return true;
601  }
602 
603  /**
604  Inequality operator. Check equality for each element
605  To do: use double tolerance
606  */
607  bool operator != (const Transform3D & rhs) const {
608  return ! operator==(rhs);
609  }
610 
611 
612 protected:
613 
614  /**
615  make transformation from first a rotation then a translation
616  */
617  void AssignFrom( const Rotation3D & r, const Vector & v);
618 
619  /**
620  make transformation from only rotations (zero translation)
621  */
622  void AssignFrom( const Rotation3D & r);
623 
624  /**
625  make transformation from only translation (identity rotations)
626  */
627  void AssignFrom( const Vector & v);
628 
629  /**
630  Set identity transformation (identity rotation , zero translation)
631  */
632  void SetIdentity() ;
633 
634 private:
635 
636 
637  double fM[12]; // transformation elements (3x4 matrix)
638 
639 };
640 
641 
642 
643 
644 // inline functions (combination of transformations)
645 
646 inline Transform3D & Transform3D::operator *= (const Transform3D & t)
647 {
648  // combination of transformations
649 
650  SetComponents(fM[kXX]*t.fM[kXX]+fM[kXY]*t.fM[kYX]+fM[kXZ]*t.fM[kZX],
651  fM[kXX]*t.fM[kXY]+fM[kXY]*t.fM[kYY]+fM[kXZ]*t.fM[kZY],
652  fM[kXX]*t.fM[kXZ]+fM[kXY]*t.fM[kYZ]+fM[kXZ]*t.fM[kZZ],
653  fM[kXX]*t.fM[kDX]+fM[kXY]*t.fM[kDY]+fM[kXZ]*t.fM[kDZ]+fM[kDX],
654 
655  fM[kYX]*t.fM[kXX]+fM[kYY]*t.fM[kYX]+fM[kYZ]*t.fM[kZX],
656  fM[kYX]*t.fM[kXY]+fM[kYY]*t.fM[kYY]+fM[kYZ]*t.fM[kZY],
657  fM[kYX]*t.fM[kXZ]+fM[kYY]*t.fM[kYZ]+fM[kYZ]*t.fM[kZZ],
658  fM[kYX]*t.fM[kDX]+fM[kYY]*t.fM[kDY]+fM[kYZ]*t.fM[kDZ]+fM[kDY],
659 
660  fM[kZX]*t.fM[kXX]+fM[kZY]*t.fM[kYX]+fM[kZZ]*t.fM[kZX],
661  fM[kZX]*t.fM[kXY]+fM[kZY]*t.fM[kYY]+fM[kZZ]*t.fM[kZY],
662  fM[kZX]*t.fM[kXZ]+fM[kZY]*t.fM[kYZ]+fM[kZZ]*t.fM[kZZ],
663  fM[kZX]*t.fM[kDX]+fM[kZY]*t.fM[kDY]+fM[kZZ]*t.fM[kDZ]+fM[kDZ]);
664 
665  return *this;
666 }
667 
668 
669 
670 inline Transform3D Transform3D::operator * (const Transform3D & t) const
671 {
672  // combination of transformations
673 
674  return Transform3D(fM[kXX]*t.fM[kXX]+fM[kXY]*t.fM[kYX]+fM[kXZ]*t.fM[kZX],
675  fM[kXX]*t.fM[kXY]+fM[kXY]*t.fM[kYY]+fM[kXZ]*t.fM[kZY],
676  fM[kXX]*t.fM[kXZ]+fM[kXY]*t.fM[kYZ]+fM[kXZ]*t.fM[kZZ],
677  fM[kXX]*t.fM[kDX]+fM[kXY]*t.fM[kDY]+fM[kXZ]*t.fM[kDZ]+fM[kDX],
678 
679  fM[kYX]*t.fM[kXX]+fM[kYY]*t.fM[kYX]+fM[kYZ]*t.fM[kZX],
680  fM[kYX]*t.fM[kXY]+fM[kYY]*t.fM[kYY]+fM[kYZ]*t.fM[kZY],
681  fM[kYX]*t.fM[kXZ]+fM[kYY]*t.fM[kYZ]+fM[kYZ]*t.fM[kZZ],
682  fM[kYX]*t.fM[kDX]+fM[kYY]*t.fM[kDY]+fM[kYZ]*t.fM[kDZ]+fM[kDY],
683 
684  fM[kZX]*t.fM[kXX]+fM[kZY]*t.fM[kYX]+fM[kZZ]*t.fM[kZX],
685  fM[kZX]*t.fM[kXY]+fM[kZY]*t.fM[kYY]+fM[kZZ]*t.fM[kZY],
686  fM[kZX]*t.fM[kXZ]+fM[kZY]*t.fM[kYZ]+fM[kZZ]*t.fM[kZZ],
687  fM[kZX]*t.fM[kDX]+fM[kZY]*t.fM[kDY]+fM[kZZ]*t.fM[kDZ]+fM[kDZ] );
688 
689 }
690 
691 
692 
693 
694 //--- global functions resulting in Transform3D -------
695 
696 
697 // ------ combination of a translation (first) and a rotation ------
698 
699 
700 /**
701  combine a translation and a rotation to give a transform3d
702  First the translation then the rotation
703  */
704 inline Transform3D operator * (const Rotation3D & r, const Translation3D & t) {
705  return Transform3D( r, r(t.Vect()) );
706 }
707 inline Transform3D operator * (const RotationX & r, const Translation3D & t) {
708  Rotation3D r3(r);
709  return Transform3D( r3, r3(t.Vect()) );
710 }
711 inline Transform3D operator * (const RotationY & r, const Translation3D & t) {
712  Rotation3D r3(r);
713  return Transform3D( r3, r3(t.Vect()) );
714 }
715 inline Transform3D operator * (const RotationZ & r, const Translation3D & t) {
716  Rotation3D r3(r);
717  return Transform3D( r3, r3(t.Vect()) );
718 }
719 inline Transform3D operator * (const RotationZYX & r, const Translation3D & t) {
720  Rotation3D r3(r);
721  return Transform3D( r3, r3(t.Vect()) );
722 }
723 inline Transform3D operator * (const AxisAngle & r, const Translation3D & t) {
724  Rotation3D r3(r);
725  return Transform3D( r3, r3(t.Vect()) );
726 }
727 inline Transform3D operator * (const EulerAngles & r, const Translation3D & t) {
728  Rotation3D r3(r);
729  return Transform3D( r3, r3(t.Vect()) );
730 }
731 inline Transform3D operator * (const Quaternion & r, const Translation3D & t) {
732  Rotation3D r3(r);
733  return Transform3D( r3, r3(t.Vect()) );
734 }
735 
736 // ------ combination of a rotation (first) and then a translation ------
737 
738 /**
739  combine a rotation and a translation to give a transform3d
740  First a rotation then the translation
741  */
742 inline Transform3D operator * (const Translation3D & t, const Rotation3D & r) {
743  return Transform3D( r, t.Vect());
744 }
745 inline Transform3D operator * (const Translation3D & t, const RotationX & r) {
746  return Transform3D( Rotation3D(r) , t.Vect());
747 }
748 inline Transform3D operator * (const Translation3D & t, const RotationY & r) {
749  return Transform3D( Rotation3D(r) , t.Vect());
750 }
751 inline Transform3D operator * (const Translation3D & t, const RotationZ & r) {
752  return Transform3D( Rotation3D(r) , t.Vect());
753 }
754 inline Transform3D operator * (const Translation3D & t, const RotationZYX & r) {
755  return Transform3D( Rotation3D(r) , t.Vect());
756 }
757 inline Transform3D operator * (const Translation3D & t, const EulerAngles & r) {
758  return Transform3D( Rotation3D(r) , t.Vect());
759 }
760 inline Transform3D operator * (const Translation3D & t, const Quaternion & r) {
761  return Transform3D( Rotation3D(r) , t.Vect());
762 }
763 inline Transform3D operator * (const Translation3D & t, const AxisAngle & r) {
764  return Transform3D( Rotation3D(r) , t.Vect());
765 }
766 
767 // ------ combination of a Transform3D and a pure translation------
768 
769 /**
770  combine a transformation and a translation to give a transform3d
771  First the translation then the transform3D
772  */
773 inline Transform3D operator * (const Transform3D & t, const Translation3D & d) {
774  Rotation3D r = t.Rotation();
775  return Transform3D( r, r( d.Vect() ) + t.Translation().Vect() );
776 }
777 
778 /**
779  combine a translation and a transformation to give a transform3d
780  First the transformation then the translation
781  */
782 inline Transform3D operator * (const Translation3D & d, const Transform3D & t) {
783  return Transform3D( t.Rotation(), t.Translation().Vect() + d.Vect());
784 }
785 
786 // ------ combination of a Transform3D and any rotation------
787 
788 
789 /**
790  combine a transformation and a rotation to give a transform3d
791  First the rotation then the transform3D
792  */
793 inline Transform3D operator * (const Transform3D & t, const Rotation3D & r) {
794  return Transform3D( t.Rotation()*r , t.Translation() );
795 }
796 inline Transform3D operator * (const Transform3D & t, const RotationX & r) {
797  return Transform3D( t.Rotation()*r , t.Translation() );
798 }
799 inline Transform3D operator * (const Transform3D & t, const RotationY & r) {
800  return Transform3D( t.Rotation()*r , t.Translation() );
801 }
802 inline Transform3D operator * (const Transform3D & t, const RotationZ & r) {
803  return Transform3D( t.Rotation()*r , t.Translation() );
804 }
805 inline Transform3D operator * (const Transform3D & t, const RotationZYX & r) {
806  return Transform3D( t.Rotation()*r , t.Translation() );
807 }
808 inline Transform3D operator * (const Transform3D & t, const EulerAngles & r) {
809  return Transform3D( t.Rotation()*r , t.Translation() );
810 }
811 inline Transform3D operator * (const Transform3D & t, const AxisAngle & r) {
812  return Transform3D( t.Rotation()*r , t.Translation() );
813 }
814 inline Transform3D operator * (const Transform3D & t, const Quaternion & r) {
815  return Transform3D( t.Rotation()*r , t.Translation() );
816 }
817 
818 
819 
820 /**
821  combine a rotation and a transformation to give a transform3d
822  First the transformation then the rotation
823  */
824 inline Transform3D operator * (const Rotation3D & r, const Transform3D & t) {
825  return Transform3D( r * t.Rotation(), r * t.Translation().Vect() );
826 }
827 inline Transform3D operator * (const RotationX & r, const Transform3D & t) {
828  Rotation3D r3d(r);
829  return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() );
830 }
831 inline Transform3D operator * (const RotationY & r, const Transform3D & t) {
832  Rotation3D r3d(r);
833  return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() );
834 }
835 inline Transform3D operator * (const RotationZ & r, const Transform3D & t) {
836  Rotation3D r3d(r);
837  return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() );
838 }
839 inline Transform3D operator * (const RotationZYX & r, const Transform3D & t) {
840  Rotation3D r3d(r);
841  return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() );
842 }
843 inline Transform3D operator * (const EulerAngles & r, const Transform3D & t) {
844  Rotation3D r3d(r);
845  return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() );
846 }
847 inline Transform3D operator * (const AxisAngle & r, const Transform3D & t) {
848  Rotation3D r3d(r);
849  return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() );
850 }
851 inline Transform3D operator * (const Quaternion & r, const Transform3D & t) {
852  Rotation3D r3d(r);
853  return Transform3D( r3d * t.Rotation(), r3d * t.Translation().Vect() );
854 }
855 
856 
857 //---I/O functions
858 // TODO - I/O should be put in the manipulator form
859 
860 /**
861  print the 12 components of the Transform3D
862  */
863 std::ostream & operator<< (std::ostream & os, const Transform3D & t);
864 
865 
866  } // end namespace Math
867 
868 } // end namespace ROOT
869 
870 
871 #endif /* ROOT_Math_GenVector_Transform3D */
Class describing a geometrical plane in 3 dimensions.
Definition: Plane3D.h:47
void GetDecomposition(Rotation3D &r, Vector &v) const
Get the rotation and translation vector representing the 3D transformation.
Definition: Transform3D.h:417
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
Definition: LorentzVector.h:54
Transform3D(const RotationY &r)
Definition: Transform3D.h:199
Transform3D(double xx, double xy, double xz, double dx, double yx, double yy, double yz, double dy, double zx, double zy, double zz, double dz)
Raw constructor from 12 Scalar components.
Definition: Transform3D.h:284
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...
void GetComponents(double &xx, double &xy, double &xz, double &dx, double &yx, double &yy, double &yz, double &dy, double &zx, double &zy, double &zz, double &dz) const
Get the components into 12 scalars.
Definition: Transform3D.h:394
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
PositionVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > Point
Definition: Transform3D.h:91
AnyRotation Rotation() const
Get the rotation representing the 3D transformation.
Definition: Transform3D.h:435
Transform3D & operator=(const ForeignMatrix &m)
Construct from a linear algebra matrix of size at least 3x4, which must support operator()(i,j) to obtain elements (0,0) thru (2,3).
Definition: Transform3D.h:299
Transform3D(const DisplacementVector3D< CoordSystem, Tag > &v)
Construct from a translation only, represented by any DisplacementVector3D and with an identity rotat...
Definition: Transform3D.h:211
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition: RotationZ.h:43
void Transform(const DisplacementVector3D< CoordSystem, Tag1 > &v1, DisplacementVector3D< CoordSystem, Tag2 > &v2) const
Transformation operation for Displacement Vector of different coordinate systems. ...
Definition: Transform3D.h:523
bool operator!=(const Transform3D &rhs) const
Inequality operator.
Definition: Transform3D.h:607
Transform3D(const Rotation3D &r, const Vector &v)
Construct from a rotation and then a translation described by a Vector.
Definition: Transform3D.h:123
void SetIdentity()
Set identity transformation (identity rotation , zero translation)
void GetComponents(IT begin, IT end) const
Get the 12 matrix components into data specified by an iterator begin and another to the end of the d...
Definition: Transform3D.h:331
Transform3D(const Vector &v)
Construct from a translation only, represented by a Cartesian 3D Vector, and with an identity rotatio...
Definition: Transform3D.h:218
void SetTransformMatrix(const ForeignMatrix &m)
Set components from a linear algebra matrix of size at least 3x4, which must support operator()(i...
Definition: Transform3D.h:358
Class describing a generic position vector (point) in 3 dimensions.
void SetComponents(double xx, double xy, double xz, double dx, double yx, double yy, double yz, double dy, double zx, double zy, double zz, double dz)
Set the components from 12 scalars.
Definition: Transform3D.h:382
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Definition: RotationZYX.h:71
Transform3D(const AxisAngle &r)
Definition: Transform3D.h:181
void GetComponents(IT begin) const
Get the 12 matrix components into data specified by an iterator begin.
Definition: Transform3D.h:346
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition: Quaternion.h:47
Transform3D(const RotationZYX &r)
Definition: Transform3D.h:190
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > Vector
Definition: Transform3D.h:90
Transform3D(const RotationX &r)
Definition: Transform3D.h:196
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition: AxisAngle.cxx:91
void GetDecomposition(AnyRotation &r, V &v) const
Get the rotation and translation vector representing the 3D transformation in any rotation and any ve...
Definition: Transform3D.h:408
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition: AxisAngle.h:41
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Definition: RotationY.h:43
unsigned int r3[N_CITIES]
Definition: simanTSP.cxx:323
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
static double p2(double t, double a, double b, double c)
Translation3D Translation() const
Get the translation representing the 3D transformation in a Cartesian vector.
Definition: Transform3D.h:452
Scalar E() const
return 4-th component (time, or energy for a 4-momentum vector)
void Transform(const PositionVector3D< CoordSystem, Tag1 > &p1, PositionVector3D< CoordSystem, Tag2 > &p2) const
Transformation operation for points between different coordinate system tags.
Definition: Transform3D.h:513
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Transform3D(const Quaternion &r)
Definition: Transform3D.h:187
Transform3D()
Default constructor (identy rotation) + zero translation.
Definition: Transform3D.h:105
Class describing a generic displacement vector in 3 dimensions.
const Vector & Vect() const
return a const reference to the underline vector representing the translation
TRandom2 r(17)
SVector< double, 2 > v
Definition: Dict.h:5
XPoint xy[kMAXMK]
Definition: TGX11.cxx:122
void AssignFrom(const Rotation3D &r, const Vector &v)
make transformation from first a rotation then a translation
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition: RotationX.h:43
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition: Rotation3D.h:65
TMarker * m
Definition: textangle.C:8
Basic 3D Transformation class describing a rotation and then a translation The internal data are a 3D...
Definition: Transform3D.h:85
Transform3D Inverse() const
Return the inverse of the transformation.
Definition: Transform3D.h:576
bool operator==(const Transform3D &rhs) const
Equality operator.
Definition: Transform3D.h:587
static double p1(double t, double a, double b)
Transform3D(const RotationZ &r)
Definition: Transform3D.h:202
Transform3D(const ARotation &r, const DisplacementVector3D< CoordSystem, Tag > &v)
Construct from a rotation (any rotation object) and then a translation (represented by any Displaceme...
Definition: Transform3D.h:142
void GetRotation(AnyRotation &r) const
Get the rotation (any type) representing the 3D transformation.
Definition: Transform3D.h:445
void GetTranslation(AnyVector &v) const
Get the translation representing the 3D transformation in any vector which implements the SetXYZ meth...
Definition: Transform3D.h:461
Rotation3D Rotation() const
Get the 3D rotation representing the 3D transformation.
Definition: Transform3D.h:425
Transform3D(const ARotation &r, const Translation3D &t)
Construct from a rotation (any rotation object) and then a translation represented by a Translation3D...
Definition: Transform3D.h:154
Transform3D(const ForeignMatrix &m)
Construct from a linear algebra matrix of size at least 3x4, which must support operator()(i,j) to obtain elements (0,0) thru (2,3).
Definition: Transform3D.h:277
void Invert()
Invert the transformation in place.
Class describing a 3 dimensional translation.
Definition: Translation3D.h:57
Transform3D(IT begin, IT end)
Construct given a pair of pointers or iterators defining the beginning and end of an array of 12 Scal...
Definition: Transform3D.h:115
EulerAngles class describing rotation as three angles (Euler Angles).
Definition: EulerAngles.h:43
Transform3D(const Rotation3D &r)
Construct from a 3D Rotation only with zero translation.
Definition: Transform3D.h:174
Namespace for new Math classes and functions.
Transform3D & operator*=(const Transform3D &t)
multiply (combine) with another transformation in place
Definition: Transform3D.h:646
Scalar Y() const
Cartesian Y, 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...
void GetTransformMatrix(ForeignMatrix &m) const
Get components into a linear algebra matrix of size at least 3x4, which must support operator()(i...
Definition: Transform3D.h:371
Point operator()(const Point &p) const
Transformation operation for Position Vector in Cartesian coordinate For a Position Vector first a ro...
Definition: Transform3D.h:473
void SetComponents(IT begin, IT end)
Set the 12 matrix components given an iterator to the start of the desired data, and another to the e...
Definition: Transform3D.h:314
DefaultCoordinateSystemTag Default tag for identifying any coordinate system.
float * q
Definition: THbookFile.cxx:87
Transform3D(const EulerAngles &r)
Definition: Transform3D.h:184
::ROOT::Math::DisplacementVector3D< Cartesian3D< Scalar > > Vect() const
get the spatial components of the Vector in a DisplacementVector based on Cartesian Coordinates ...
Transform3D(const Translation3D &t)
Construct from a translation only, represented by a Translation3D class and with an identity rotation...
Definition: Transform3D.h:225
Transform3D(const Rotation3D &r, const Translation3D &t)
Construct from a rotation and then a translation described by a Translation3D class.
Definition: Transform3D.h:130
AVector operator*(const AVector &v) const
Transformation operation for Vectors.
Definition: Transform3D.h:552