TransformationMatrix.cc
Go to the documentation of this file.
1 
9 #include <utl/config.h>
10 #include <utl/TransformationMatrix.h>
11 #include <CLHEP/Geometry/Transform3D.h>
12 #include <cmath>
13 #include <iostream>
14 
15 using namespace utl;
16 
17 
18 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
19  * Functions and operators
20  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
21 
24 {
25  fTransform = fTransform * second.fTransform;
26  return *this;
27 }
28 
29 
39 double
41  const
42 {
43  // the internal class provide access to the interal data of a HepGeom::Transform3D
44  class TransformWithDistance : public HepGeom::Transform3D {
45  public:
46  TransformWithDistance(const HepGeom::Transform3D& t)
47  : HepGeom::Transform3D(t) { }
48  double Distance(const TransformWithDistance& t) {
49  const double d2 =
50  (xx_-t.xx_)*(xx_-t.xx_) + (xy_-t.xy_)*(xy_-t.xy_) + (xz_-t.xz_)*(xz_-t.xz_) +
51  (yx_-t.yx_)*(yx_-t.yx_) + (yy_-t.yy_)*(yy_-t.yy_) + (yz_-t.yz_)*(yz_-t.yz_) +
52  (zx_-t.zx_)*(zx_-t.zx_) + (zy_-t.zy_)*(zy_-t.zy_) + (zz_-t.zz_)*(zz_-t.zz_) +
53  (dx_-t.dx_)*(dx_-t.dx_) + (dy_-t.dy_)*(dy_-t.dy_) + (dz_-t.dz_)*(dz_-t.dz_);
54  return sqrt(d2);
55  }
56  };
57 
58  return TransformWithDistance(this->fTransform).Distance(second.fTransform);
59 }
60 
61 
64  const
65 {
66  return TransformationMatrix(fTransform.inverse());
67 }
68 
69 
70 boost::tuple<TransformationMatrix, TransformationMatrix>
72  const
73 {
74  HepGeom::Scale3D scale;
75  HepGeom::Rotate3D rotation;
76  HepGeom::Translate3D translation;
77 
78  fTransform.getDecomposition(scale, rotation, translation);
79 
80  return boost::make_tuple(TransformationMatrix(translation),
81  TransformationMatrix(rotation));
82 }
83 
84 
85 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
86  * Factory functions
87  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
88 
93 TransformationMatrix::Translation(const double x, const double y, const double z)
94 {
95  return TransformationMatrix(HepGeom::Translate3D(x, y, z));
96 }
97 
98 
104  const double x, const double y, const double z)
105 {
106  return TransformationMatrix(HepGeom::Rotate3D(angle, HepGeom::Vector3D<double>(x, y, z)));
107 }
108 
109 
114 TransformationMatrix::Rotation(const double angle, const Triple& v)
115 {
116  return
118  HepGeom::Rotate3D(angle, HepGeom::Vector3D<double>(v.get<0>(), v.get<1>(), v.get<2>()))
119  );
120 }
121 
122 
128 {
129  return TransformationMatrix(HepGeom::RotateX3D(angle));
130 }
131 
132 
138 {
139  return TransformationMatrix(HepGeom::RotateY3D(angle));
140 }
141 
142 
148 {
149  return TransformationMatrix(HepGeom::RotateZ3D(angle));
150 }
151 
152 
154 TransformationMatrix::TransformToBasis(const double x1, const double y1, const double z1,
155  const double x2, const double y2, const double z2,
156  const double x3, const double y3, const double z3)
157 {
158  class TC : public HepGeom::Transform3D {
159  public:
160  TC(const double xx, const double xy, const double xz,
161  const double yx, const double yy, const double yz,
162  const double zx, const double zy, const double zz)
163  : HepGeom::Transform3D(xx, xy, xz, 0,
164  yx, yy, yz, 0,
165  zx, zy, zz, 0) { }
166  };
167 
168  return TransformationMatrix(TC(x1, y1, z1,
169  x2, y2, z2,
170  x3, y3, z3));
171 }
172 
173 
174 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
175  * non-member functions
176  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
177 
181 std::ostream&
182 utl::operator<<(std::ostream& s, const TransformationMatrix& m)
183 {
184  s << '[';
185  for (int i = 0; i < TransformationMatrix::kDimension; ++i) {
186  s << (i ? " " : "") << '[';
187  for (int j = 0; j < TransformationMatrix::kDimension; ++j)
188  s << (i ? " " : "") << m.fTransform(i, j);
189  s << ']';
190  }
191  return s << ']';
192 }
193 
194 
195 // Configure (x)emacs for this file ...
196 // Local Variables:
197 // mode: c++
198 // compile-command: "make -C .. -k"
199 // End:
boost::tuple< TransformationMatrix, TransformationMatrix > Decompose() const
Decomposition into Translation and Rotation.
constexpr double second
Definition: AugerUnits.h:145
TransformationMatrix & operator*=(const TransformationMatrix &second)
Chaining of transformations.
static TransformationMatrix TransformToBasis(const double x1, const double y1, const double z1, const double x2, const double y2, const double z2, const double x3, const double y3, const double z3)
From dreibein (basis vectors)
boost::tuple< double, double, double > Triple
static TransformationMatrix RotationX(const double angle)
Rotation by angle about X axis.
Stream & operator<<(Stream &s, MessageLoggerConfig &mlc)
Applies the configuration to the given stream.
static TransformationMatrix Rotation(const double angle, const double x, const double y, const double z)
Rotation by angle about axis given by three components.
Transformations matrices for afine transformations.
double Distance(const TransformationMatrix &second) const
Distance between transformations (useful for testing)
static const int kDimension
Dimension of transformation matrix.
constexpr double s
Definition: AugerUnits.h:163
static TransformationMatrix Translation(const double x, const double y, const double z)
Translation.
TransformationMatrix Inverse() const
Inverse transformation.
static TransformationMatrix RotationZ(const double angle)
Rotation by angle about Z axis.
constexpr double m
Definition: AugerUnits.h:121
InternalTransform fTransform
The concrete transformation object.
static TransformationMatrix RotationY(const double angle)
Rotation by angle about Y axis.

, generated on Tue Sep 26 2023.