CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

testTransform3D.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id: testTransform3D.cc,v 1.3 2003/10/24 21:39:45 garren Exp $
3 // ---------------------------------------------------------------------------
4 //
5 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
6 //
7 // This is a test for the HepGeom::Transform3D class.
8 //
9 #include <assert.h>
11 #include "CLHEP/Vector/Rotation.h"
12 #include "CLHEP/Vector/ThreeVector.h"
13 #include "CLHEP/Units/PhysicalConstants.h"
14 
22 
23 #define DEL 10.e-16
24 
25 int main() {
26  int i,k;
27  double E[4][4] = {
28  { 1, 0, 0, 0},
29  { 0, 1, 0, 0},
30  { 0, 0, 1, 0},
31  { 0, 0, 0, 1}
32  };
33 
34  // Default constructor
35 
37  for (i=0; i<4; i++) {
38  for (k=0; k<4; k++) {
39  assert ( M[i][k] == E[i][k] );
40  }
41  }
42  assert ( M == Transformation::Identity );
43 
44  // Rotation + Translation
45 
46  HepRotation R;
47  double angA=CLHEP::pi/3, angB=CLHEP::pi/4, angC=CLHEP::pi/6;
48 
49  R.rotateX(angA); R.rotateY(angB); R.rotateZ(angC);
50  const Hep3Vector D(1, 2, 3);
51  M = Transformation(R,D);
52 
53  for (i=0; i<3; i++) {
54  for (k=0; k<3; k++) { assert ( M[i][k] == R[i][k] ); }
55  }
56  assert ( M(0,3) == D.x() );
57  assert ( M(1,3) == D.y() );
58  assert ( M(2,3) == D.z() );
59 
60  // Transformation of point, vector, normal
61 
62  const Point p0(1,1,1);
63  const Vector v0(1,1,1);
64  const Normal n0(1,1,1);
65 
66  Point p1 = M * p0;
67  Point p2 = R*Hep3Vector(1,1,1) + D;
68  assert( std::abs(p1.x()-p2.x()) < DEL );
69  assert( std::abs(p1.y()-p2.y()) < DEL );
70  assert( std::abs(p1.z()-p2.z()) < DEL );
71 
72  Vector v1 = M * v0;
73  Normal n1 = M * n0;
74  assert( std::abs(v1.x()-n1.x()) < DEL );
75  assert( std::abs(v1.y()-n1.y()) < DEL );
76  assert( std::abs(v1.z()-n1.z()) < DEL );
77 
78  // Transformation of basis
79 
80  p1 = Point(M[0][0]+D.x(), M[1][0]+D.y(), M[2][0]+D.z());
81  p2 = Point(M[0][1]+D.x(), M[1][1]+D.y(), M[2][1]+D.z());
82  Transformation T(Point(0,0,0), Point(1,0,0), Point(0,1,0), D, p1, p2);
83 
84  for (i=0; i<4; i++) {
85  for (k=0; k<4; k++) { assert ( std::abs(M[i][k] - T[i][k]) < DEL ); }
86  }
87 
88  // Set Identity
89 
90  T.setIdentity();
91  for (i=0; i<4; i++) {
92  for (k=0; k<4; k++) { assert ( T[i][k] == E[i][k] ); }
93  }
94 
95  // Assignment, fortran-style subscripting
96 
97  T = M;
98  assert (T == M);
99  for (i=0; i<4; i++) {
100  for (k=0; k<4; k++) { assert ( T(i,k) == M[i][k] ); }
101  }
102 
103  // Inversion
104 
105  T = M.inverse();
106  assert (T != M);
107  T = M * T;
108  for (i=0; i<4; i++) {
109  for (k=0; k<4; k++) { assert ( std::abs(T[i][k] - E[i][k]) < DEL ); }
110  }
111 
112  T = M.inverse();
113  T = T * M;
114  for (i=0; i<4; i++) {
115  for (k=0; k<4; k++) { assert ( std::abs(T[i][k] - E[i][k]) < DEL ); }
116  }
117 
118  // Get Rotation
119 
120  HepRotation Q;
121  Q = M.getRotation();
122  for (i=0; i<3; i++) {
123  for (k=0; k<3; k++) { assert ( R[i][k] == Q[i][k] ); }
124  }
125 
126  // Get Translation
127 
128  Hep3Vector C;
129  C = M.getTranslation();
130  assert ( C.x() == D.x() );
131  assert ( C.y() == D.y() );
132  assert ( C.z() == D.z() );
133 
134  // Compound transformation
135  // Get Decomposition
136 
137  Scale S(-2,3,4);
138  M = Transformation(R,D)*S;
139 
140  Scale SS;
141  Rotation RR;
142  Translation TT;
143  M.getDecomposition(SS,RR,TT);
144 
145  S = HepGeom::Scale3D(2,3,-4);
146  T = TT*RR*SS;
147  for (i=0; i<4; i++) {
148  for (k=0; k<4; k++) {
149  assert ( std::abs(S[i][k] - SS[i][k]) < DEL );
150  assert ( std::abs(M[i][k] - T[i][k]) < DEL );
151  }
152  }
153 
154  // test for isNear()
155 
156  assert ( T.isNear(M, DEL) );
157  S = HepGeom::Scale3D(2.01,3,-4);
158  T = TT*RR*S;
159  assert ( !T.isNear(M) );
160 
161  // Different conversions
162 
163  Hep3Vector www(1,2,3);
164  Vector vvv;
165  Point ppp(3,2,1);
166  Normal nnn;
167 
168  vvv = www;
169  www = vvv;
170  nnn = ppp;
171 
172  assert (vvv.x() == nnn.z());
173  assert (vvv.y() == nnn.y());
174  assert (vvv.z() == nnn.x());
175 
176  nnn = Normal(ppp);
177  www = Hep3Vector(vvv);
178 
179  return 0;
180 }
HepGeom::Transform3D::setIdentity
void setIdentity()
Definition: CLHEP/Geometry/Transform3D.h:299
HepGeom::Point3D< double >
Definition: CLHEP/Geometry/Point3D.h:123
HepGeom::Scale3D
Definition: CLHEP/Geometry/Transform3D.h:726
HepGeom::BasicVector3D::y
T y() const
Definition: CLHEP/Geometry/BasicVector3D.h:145
DEL
#define DEL
Definition: testTransform3D.cc:23
HepGeom::BasicVector3D::z
T z() const
Definition: CLHEP/Geometry/BasicVector3D.h:148
HepGeom::Transform3D::getDecomposition
void getDecomposition(Scale3D &scale, Rotate3D &rotation, Translate3D &translation) const
Definition: Transform3D.cc:178
D
Definition: excDblThrow.cc:17
Scale
HepGeom::Scale3D Scale
Definition: testTransform3D.cc:15
Vector
HepGeom::Vector3D< double > Vector
Definition: testTransform3D.cc:20
Hep3Vector
Issues Concerning the PhysicsVectors CLHEP Vector Merge The merge of ZOOM PhysicsVdectors and the CLHEP Vector package is completed The purpose of this document is to list the major issues that affected the merge of these and where relevant describe the resolutions More detailed documents describe more minor issues General Approach As agreed at the June CLHEP the approach is to combine the features of each ZOOM class with the corresponding CLHEP class expanding the interface to create a single lingua franca of what a Hep3Vector(for example) means. We are not forming SpaceVector as an class derived from Hep3Vector and enhancing it in that way. Another rule imposed by the agreement is to avoid using the Exceptions package(even though that will later go into CLHEP for other uses). A desirable goal is to avoid cluttering the interface and enlarging the code linked in when ordinary CLHEP Vector functionallity is used. To this end
n_constructors::p0
incomplete * p0
Definition: testSharedPtr.cc:393
HepGeom::Transform3D
Definition: CLHEP/Geometry/Transform3D.h:172
HepGeom::Translate3D
Definition: CLHEP/Geometry/Transform3D.h:516
HepGeom::Transform3D::inverse
Transform3D inverse() const
Definition: Transform3D.cc:146
Rotation
HepGeom::Rotate3D Rotation
Definition: testTransform3D.cc:16
Transform3D.h
HepGeom::Vector3D< double >
Definition: CLHEP/Geometry/Vector3D.h:102
Point
HepGeom::Point3D< double > Point
Definition: testTransform3D.cc:19
HepGeom::Transform3D::Identity
static const Transform3D Identity
Definition: CLHEP/Geometry/Transform3D.h:198
Normal
HepGeom::Normal3D< double > Normal
Definition: testTransform3D.cc:21
i
long i
Definition: JamesRandomSeeding.txt:27
Translation
HepGeom::Translate3D Translation
Definition: testTransform3D.cc:17
HepGeom::Rotate3D
Definition: CLHEP/Geometry/Transform3D.h:375
main
int main()
Definition: testTransform3D.cc:25
R
Application of Rotations and LorentzTransformations to containers of and as in Rotation R
Definition: keyMergeIssues.doc:333
HepGeom::BasicVector3D::x
T x() const
Definition: CLHEP/Geometry/BasicVector3D.h:142
k
long k
Definition: JamesRandomSeeding.txt:29
HepGeom::Normal3D< double >
Definition: CLHEP/Geometry/Normal3D.h:102
Transformation
HepGeom::Transform3D Transformation
Definition: testTransform3D.cc:18