CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
HepGeom::Transform3D Class Reference

#include <Transform3D.h>

+ Inheritance diagram for HepGeom::Transform3D:

Classes

class  Transform3D_row
 

Public Member Functions

 Transform3D ()
 
 Transform3D (const CLHEP::HepRotation &mt, const CLHEP::Hep3Vector &v)
 
 Transform3D (const Point3D< double > &fr0, const Point3D< double > &fr1, const Point3D< double > &fr2, const Point3D< double > &to0, const Point3D< double > &to1, const Point3D< double > &to2)
 
 Transform3D (const Transform3D &mt)=default
 
 Transform3D (Transform3D &&mt)=default
 
 ~Transform3D ()=default
 
Transform3Doperator= (const Transform3D &mt)=default
 
Transform3Doperator= (Transform3D &&mt)=default
 
const Transform3D_row operator[] (int) const
 
double operator() (int, int) const
 
double xx () const
 
double xy () const
 
double xz () const
 
double yx () const
 
double yy () const
 
double yz () const
 
double zx () const
 
double zy () const
 
double zz () const
 
double dx () const
 
double dy () const
 
double dz () const
 
void setIdentity ()
 
Transform3D inverse () const
 
Transform3D operator* (const Transform3D &b) const
 
void getDecomposition (Scale3D &scale, Rotate3D &rotation, Translate3D &translation) const
 
bool isNear (const Transform3D &t, double tolerance=2.2E-14) const
 
CLHEP::HepRotation getRotation () const
 
CLHEP::Hep3Vector getTranslation () const
 
bool operator== (const Transform3D &transform) const
 
bool operator!= (const Transform3D &transform) const
 

Static Public Attributes

static const Transform3D Identity = Transform3D ()
 

Protected Member Functions

 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)
 
void setTransform (double XX, double XY, double XZ, double DX, double YX, double YY, double YZ, double DY, double ZX, double ZY, double ZZ, double DZ)
 

Protected Attributes

double xx_
 
double xy_
 
double xz_
 
double dx_
 
double yx_
 
double yy_
 
double yz_
 
double dy_
 
double zx_
 
double zy_
 
double zz_
 
double dz_
 

Detailed Description

Class for transformation of 3D geometrical objects. It allows different translations, rotations, scalings and reflections. Several specialized classes are derived from it:

TranslateX3D, TranslateY3D, TranslateZ3D, Translate3D,
RotateX3D, RotateY3D, RotateZ3D, Rotate3D,
ScaleX3D, ScaleY3D, ScaleZ3D, Scale3D,
ReflectX3D, ReflectY3D, ReflectZ3D, Reflect3D.

The idea behind these classes is to provide some additional constructors for Transform3D, they normally should not be used as separate classes.

Example:

Remark: For the reason that the operator* is left associative, the notation

v2 = m3*(m2*(m1*v1));

is much more effective then the notation

v2 = m3*m2*m1*v1;

In the first case three operations Transform3D*Vector3D are executed, in the second case two operations Transform3D*Transform3D and one Transform3D*Vector3D are performed. Transform3D*Transform3D is roughly three times slower than Transform3D*Vector3D.

Author
Evgue.nosp@m.ni.T.nosp@m.chern.nosp@m.iaev.nosp@m.@cern.nosp@m..ch

Definition at line 172 of file Transform3D.h.

Constructor & Destructor Documentation

◆ Transform3D() [1/6]

HepGeom::Transform3D::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 
)
inlineprotected

Definition at line 179 of file Transform3D.h.

182 : xx_(XX), xy_(XY), xz_(XZ), dx_(DX),
183 yx_(YX), yy_(YY), yz_(YZ), dy_(DY),
184 zx_(ZX), zy_(ZY), zz_(ZZ), dz_(DZ) {}

◆ Transform3D() [2/6]

HepGeom::Transform3D::Transform3D ( )
inline

Default constructor - sets the Identity transformation.

Definition at line 212 of file Transform3D.h.

213 : xx_(1), xy_(0), xz_(0), dx_(0),
214 yx_(0), yy_(1), yz_(0), dy_(0),
215 zx_(0), zy_(0), zz_(1), dz_(0) {}

Referenced by inverse(), and operator*().

◆ Transform3D() [3/6]

HepGeom::Transform3D::Transform3D ( const CLHEP::HepRotation mt,
const CLHEP::Hep3Vector v 
)
inline

Constructor: rotation and then translation.

◆ Transform3D() [4/6]

HepGeom::Transform3D::Transform3D ( const Point3D< double > &  fr0,
const Point3D< double > &  fr1,
const Point3D< double > &  fr2,
const Point3D< double > &  to0,
const Point3D< double > &  to1,
const Point3D< double > &  to2 
)

Constructor: transformation of basis (assumed - no reflection).

Definition at line 64 of file Transform3D.cc.

81 {
82 Vector3D<double> x1,y1,z1, x2,y2,z2;
83 x1 = (fr1 - fr0).unit();
84 y1 = (fr2 - fr0).unit();
85 x2 = (to1 - to0).unit();
86 y2 = (to2 - to0).unit();
87
88 // C H E C K A N G L E S
89
90 double cos1, cos2;
91 cos1 = x1*y1;
92 cos2 = x2*y2;
93
94 if (std::abs(1.0-cos1) <= 0.000001 || std::abs(1.0-cos2) <= 0.000001) {
95 std::cerr << "Transform3D: zero angle between axes" << std::endl;
97 }else{
98 if (std::abs(cos1-cos2) > 0.000001) {
99 std::cerr << "Transform3D: angles between axes are not equal"
100 << std::endl;
101 }
102
103 // F I N D R O T A T I O N M A T R I X
104
105 z1 = (x1.cross(y1)).unit();
106 y1 = z1.cross(x1);
107
108 z2 = (x2.cross(y2)).unit();
109 y2 = z2.cross(x2);
110
111 double detxx = (y1.y()*z1.z() - z1.y()*y1.z());
112 double detxy = -(y1.x()*z1.z() - z1.x()*y1.z());
113 double detxz = (y1.x()*z1.y() - z1.x()*y1.y());
114 double detyx = -(x1.y()*z1.z() - z1.y()*x1.z());
115 double detyy = (x1.x()*z1.z() - z1.x()*x1.z());
116 double detyz = -(x1.x()*z1.y() - z1.x()*x1.y());
117 double detzx = (x1.y()*y1.z() - y1.y()*x1.z());
118 double detzy = -(x1.x()*y1.z() - y1.x()*x1.z());
119 double detzz = (x1.x()*y1.y() - y1.x()*x1.y());
120
121 double txx = x2.x()*detxx + y2.x()*detyx + z2.x()*detzx;
122 double txy = x2.x()*detxy + y2.x()*detyy + z2.x()*detzy;
123 double txz = x2.x()*detxz + y2.x()*detyz + z2.x()*detzz;
124 double tyx = x2.y()*detxx + y2.y()*detyx + z2.y()*detzx;
125 double tyy = x2.y()*detxy + y2.y()*detyy + z2.y()*detzy;
126 double tyz = x2.y()*detxz + y2.y()*detyz + z2.y()*detzz;
127 double tzx = x2.z()*detxx + y2.z()*detyx + z2.z()*detzx;
128 double tzy = x2.z()*detxy + y2.z()*detyy + z2.z()*detzy;
129 double tzz = x2.z()*detxz + y2.z()*detyz + z2.z()*detzz;
130
131 // S E T T R A N S F O R M A T I O N
132
133 double dx1 = fr0.x(), dy1 = fr0.y(), dz1 = fr0.z();
134 double dx2 = to0.x(), dy2 = to0.y(), dz2 = to0.z();
135
136 setTransform(txx, txy, txz, dx2-txx*dx1-txy*dy1-txz*dz1,
137 tyx, tyy, tyz, dy2-tyx*dx1-tyy*dy1-tyz*dz1,
138 tzx, tzy, tzz, dz2-tzx*dx1-tzy*dy1-tzz*dz1);
139 }
140 }
void setTransform(double XX, double XY, double XZ, double DX, double YX, double YY, double YZ, double DY, double ZX, double ZY, double ZZ, double DZ)
Definition: Transform3D.h:187

◆ Transform3D() [5/6]

HepGeom::Transform3D::Transform3D ( const Transform3D mt)
default

Copy constructor.

◆ Transform3D() [6/6]

HepGeom::Transform3D::Transform3D ( Transform3D &&  mt)
default

Move constructor.

◆ ~Transform3D()

HepGeom::Transform3D::~Transform3D ( )
default

Destructor.

Member Function Documentation

◆ dx()

double HepGeom::Transform3D::dx ( ) const
inline

Gets dx-element of the transformation matrix.

Definition at line 286 of file Transform3D.h.

286{ return dx_; }

Referenced by HepGeom::Point3D< T >::operator*(), HepGeom::Point3D< float >::transform(), and HepGeom::Point3D< double >::transform().

◆ dy()

double HepGeom::Transform3D::dy ( ) const
inline

Gets dy-element of the transformation matrix.

Definition at line 289 of file Transform3D.h.

289{ return dy_; }

Referenced by HepGeom::Point3D< T >::operator*(), HepGeom::Point3D< float >::transform(), and HepGeom::Point3D< double >::transform().

◆ dz()

double HepGeom::Transform3D::dz ( ) const
inline

Gets dz-element of the transformation matrix.

Definition at line 292 of file Transform3D.h.

292{ return dz_; }

Referenced by HepGeom::Point3D< T >::operator*(), HepGeom::Point3D< float >::transform(), and HepGeom::Point3D< double >::transform().

◆ getDecomposition()

void HepGeom::Transform3D::getDecomposition ( Scale3D scale,
Rotate3D rotation,
Translate3D translation 
) const

Decomposition of general transformation. This function gets decomposition of the transformation in three consequentive specific transformations: Scale3D, then Rotate3D, then Translate3, i.e.

Parameters
scaleoutput: scaling transformation; if there was a reflection, then scale factor for z-component (scale(2,2)) will be negative.
rotationoutput: rotation transformaion.
translationoutput: translation transformaion.

Definition at line 175 of file Transform3D.cc.

189 {
190 double sx = std::sqrt(xx_*xx_ + yx_*yx_ + zx_*zx_);
191 double sy = std::sqrt(xy_*xy_ + yy_*yy_ + zy_*zy_);
192 double sz = std::sqrt(xz_*xz_ + yz_*yz_ + zz_*zz_);
193
194 if (xx_*(yy_*zz_-yz_*zy_) -
195 xy_*(yx_*zz_-yz_*zx_) +
196 xz_*(yx_*zy_-yy_*zx_) < 0) sz = -sz;
197 scale.setTransform(sx,0,0,0, 0,sy,0,0, 0,0,sz,0);
198 rotation.setTransform(xx_/sx,xy_/sy,xz_/sz,0,
199 yx_/sx,yy_/sy,yz_/sz,0,
200 zx_/sx,zy_/sy,zz_/sz,0);
201 translation.setTransform(1,0,0,dx_, 0,1,0,dy_, 0,0,1,dz_);
202 }

Referenced by main().

◆ getRotation()

CLHEP::HepRotation HepGeom::Transform3D::getRotation ( ) const
inline

Extracts the rotation matrix. This functions is obsolete - use getDecomposition() instead.

Referenced by main(), and XF::Pow::operator()().

◆ getTranslation()

CLHEP::Hep3Vector HepGeom::Transform3D::getTranslation ( ) const
inline

Extracts the translation vector. This functions is obsolete - use getDecomposition() instead.

Referenced by main(), and XF::Pow::operator()().

◆ inverse()

Transform3D HepGeom::Transform3D::inverse ( ) const

Returns the inverse transformation.

Definition at line 143 of file Transform3D.cc.

152 {
153 double detxx = yy_*zz_-yz_*zy_;
154 double detxy = yx_*zz_-yz_*zx_;
155 double detxz = yx_*zy_-yy_*zx_;
156 double det = xx_*detxx - xy_*detxy + xz_*detxz;
157 if (det == 0) {
158 std::cerr << "Transform3D::inverse error: zero determinant" << std::endl;
159 return Transform3D();
160 }
161 det = 1./det; detxx *= det; detxy *= det; detxz *= det;
162 double detyx = (xy_*zz_ - xz_*zy_)*det;
163 double detyy = (xx_*zz_ - xz_*zx_)*det;
164 double detyz = (xx_*zy_ - xy_*zx_)*det;
165 double detzx = (xy_*yz_ - xz_*yy_)*det;
166 double detzy = (xx_*yz_ - xz_*yx_)*det;
167 double detzz = (xx_*yy_ - xy_*yx_)*det;
168 return Transform3D
169 (detxx, -detyx, detzx, -detxx*dx_+detyx*dy_-detzx*dz_,
170 -detxy, detyy, -detzy, detxy*dx_-detyy*dy_+detzy*dz_,
171 detxz, -detyz, detzz, -detxz*dx_+detyz*dy_-detzz*dz_);
172 }

Referenced by main().

◆ isNear()

bool HepGeom::Transform3D::isNear ( const Transform3D t,
double  tolerance = 2.2E-14 
) const

Returns true if the difference between corresponding matrix elements is less than the tolerance.

Definition at line 205 of file Transform3D.cc.

206 {
207 return ( (std::abs(xx_ - t.xx_) <= tolerance) &&
208 (std::abs(xy_ - t.xy_) <= tolerance) &&
209 (std::abs(xz_ - t.xz_) <= tolerance) &&
210 (std::abs(dx_ - t.dx_) <= tolerance) &&
211 (std::abs(yx_ - t.yx_) <= tolerance) &&
212 (std::abs(yy_ - t.yy_) <= tolerance) &&
213 (std::abs(yz_ - t.yz_) <= tolerance) &&
214 (std::abs(dy_ - t.dy_) <= tolerance) &&
215 (std::abs(zx_ - t.zx_) <= tolerance) &&
216 (std::abs(zy_ - t.zy_) <= tolerance) &&
217 (std::abs(zz_ - t.zz_) <= tolerance) &&
218 (std::abs(dz_ - t.dz_) <= tolerance) );
219 }

Referenced by main().

◆ operator!=()

bool HepGeom::Transform3D::operator!= ( const Transform3D transform) const
inline

Test for inequality.

Definition at line 351 of file Transform3D.h.

351 {
352 return ! operator==(transform);
353 }
bool operator==(const Transform3D &transform) const
Definition: Transform3D.cc:222

◆ operator()()

double HepGeom::Transform3D::operator() ( int  i,
int  j 
) const

Fortran-style subscripting: returns (i,j) element of the matrix.

Definition at line 25 of file Transform3D.cc.

25 {
26 if (i == 0) {
27 if (j == 0) { return xx_; }
28 if (j == 1) { return xy_; }
29 if (j == 2) { return xz_; }
30 if (j == 3) { return dx_; }
31 } else if (i == 1) {
32 if (j == 0) { return yx_; }
33 if (j == 1) { return yy_; }
34 if (j == 2) { return yz_; }
35 if (j == 3) { return dy_; }
36 } else if (i == 2) {
37 if (j == 0) { return zx_; }
38 if (j == 1) { return zy_; }
39 if (j == 2) { return zz_; }
40 if (j == 3) { return dz_; }
41 } else if (i == 3) {
42 if (j == 0) { return 0.0; }
43 if (j == 1) { return 0.0; }
44 if (j == 2) { return 0.0; }
45 if (j == 3) { return 1.0; }
46 }
47 std::cerr << "Transform3D subscripting: bad indices "
48 << "(" << i << "," << j << ")" << std::endl;
49 return 0.0;
50 }

◆ operator*()

Transform3D HepGeom::Transform3D::operator* ( const Transform3D b) const

Transformation by another Transform3D.

Definition at line 53 of file Transform3D.cc.

53 {
54 return Transform3D
55 (xx_*b.xx_+xy_*b.yx_+xz_*b.zx_, xx_*b.xy_+xy_*b.yy_+xz_*b.zy_,
56 xx_*b.xz_+xy_*b.yz_+xz_*b.zz_, xx_*b.dx_+xy_*b.dy_+xz_*b.dz_+dx_,
57 yx_*b.xx_+yy_*b.yx_+yz_*b.zx_, yx_*b.xy_+yy_*b.yy_+yz_*b.zy_,
58 yx_*b.xz_+yy_*b.yz_+yz_*b.zz_, yx_*b.dx_+yy_*b.dy_+yz_*b.dz_+dy_,
59 zx_*b.xx_+zy_*b.yx_+zz_*b.zx_, zx_*b.xy_+zy_*b.yy_+zz_*b.zy_,
60 zx_*b.xz_+zy_*b.yz_+zz_*b.zz_, zx_*b.dx_+zy_*b.dy_+zz_*b.dz_+dz_);
61 }

◆ operator=() [1/2]

Transform3D & HepGeom::Transform3D::operator= ( const Transform3D mt)
default

Assignment.

◆ operator=() [2/2]

Transform3D & HepGeom::Transform3D::operator= ( Transform3D &&  mt)
default

Move assignment.

◆ operator==()

bool HepGeom::Transform3D::operator== ( const Transform3D transform) const

Test for equality.

Definition at line 222 of file Transform3D.cc.

223 {
224 return (this == &t) ? true :
225 (xx_==t.xx_ && xy_==t.xy_ && xz_==t.xz_ && dx_==t.dx_ &&
226 yx_==t.yx_ && yy_==t.yy_ && yz_==t.yz_ && dy_==t.dy_ &&
227 zx_==t.zx_ && zy_==t.zy_ && zz_==t.zz_ && dz_==t.dz_ );
228 }

Referenced by operator!=().

◆ operator[]()

const Transform3D_row HepGeom::Transform3D::operator[] ( int  ) const
inline

Returns object of the helper class for C-style subscripting r[i][j]

◆ setIdentity()

void HepGeom::Transform3D::setIdentity ( )
inline

Sets the Identity transformation.

Definition at line 296 of file Transform3D.h.

296 {
297 xy_= xz_= dx_= yx_= yz_= dy_= zx_= zy_= dz_= 0; xx_= yy_= zz_= 1;
298 }

Referenced by main(), HepGeom::Reflect3D::Reflect3D(), and Transform3D().

◆ setTransform()

void HepGeom::Transform3D::setTransform ( double  XX,
double  XY,
double  XZ,
double  DX,
double  YX,
double  YY,
double  YZ,
double  DY,
double  ZX,
double  ZY,
double  ZZ,
double  DZ 
)
inlineprotected

Definition at line 187 of file Transform3D.h.

189 {
190 xx_ = XX; xy_ = XY; xz_ = XZ; dx_ = DX;
191 yx_ = YX; yy_ = YY; yz_ = YZ; dy_ = DY;
192 zx_ = ZX; zy_ = ZY; zz_ = ZZ; dz_ = DZ;
193 }

Referenced by HepGeom::Reflect3D::Reflect3D(), HepGeom::Rotate3D::Rotate3D(), HepGeom::RotateX3D::RotateX3D(), HepGeom::RotateY3D::RotateY3D(), HepGeom::RotateZ3D::RotateZ3D(), and Transform3D().

◆ xx()

◆ xy()

◆ xz()

◆ yx()

◆ yy()

◆ yz()

◆ zx()

◆ zy()

◆ zz()

Member Data Documentation

◆ dx_

double HepGeom::Transform3D::dx_
protected

◆ dy_

double HepGeom::Transform3D::dy_
protected

◆ dz_

double HepGeom::Transform3D::dz_
protected

◆ Identity

const Transform3D HepGeom::Transform3D::Identity = Transform3D ()
static

Global identity transformation.

Definition at line 198 of file Transform3D.h.

Referenced by main().

◆ xx_

double HepGeom::Transform3D::xx_
protected

◆ xy_

double HepGeom::Transform3D::xy_
protected

◆ xz_

double HepGeom::Transform3D::xz_
protected

◆ yx_

double HepGeom::Transform3D::yx_
protected

◆ yy_

double HepGeom::Transform3D::yy_
protected

◆ yz_

double HepGeom::Transform3D::yz_
protected

◆ zx_

double HepGeom::Transform3D::zx_
protected

◆ zy_

double HepGeom::Transform3D::zy_
protected

◆ zz_

double HepGeom::Transform3D::zz_
protected

The documentation for this class was generated from the following files: