13 #pragma implementation
16 #include "CLHEP/Vector/Rotation.h"
24 bool HepRotation::setCols
25 (
const Hep3Vector & u1,
const Hep3Vector & u2,
const Hep3Vector & u3,
27 Hep3Vector & v1, Hep3Vector & v2, Hep3Vector & v3 )
const {
30 std::cerr <<
"HepRotation::setCols() - "
31 <<
"All three cols supplied for a Rotation are parallel --"
32 <<
"\n an arbitrary rotation will be returned" << std::endl;
33 setArbitrarily (u1, v1, v2, v3);
38 v2 = Hep3Vector(u2 - u1u2 * u1).unit();
40 if ( v3.dot(u3) >= 0 ) {
48 void HepRotation::setArbitrarily (
const Hep3Vector & ccolX,
49 Hep3Vector & v1, Hep3Vector & v2, Hep3Vector & v3)
const {
55 v2 = v1.cross(Hep3Vector(0,0,1));
59 v2 = Hep3Vector(1,0,0);
73 HepRotation & HepRotation::set(
const Hep3Vector & ccolX,
74 const Hep3Vector & ccolY,
75 const Hep3Vector & ccolZ ) {
76 Hep3Vector ucolX = ccolX.unit();
77 Hep3Vector ucolY = ccolY.unit();
78 Hep3Vector ucolZ = ccolZ.unit();
80 double u1u2 = ucolX.dot(ucolY);
81 double f12 = std::fabs(u1u2);
83 std::cerr <<
"HepRotation::set() - "
84 <<
"col's X and Y supplied for Rotation are not close to orthogonal"
87 double u1u3 = ucolX.dot(ucolZ);
88 double f13 = std::fabs(u1u3);
90 std::cerr <<
"HepRotation::set() - "
91 <<
"col's X and Z supplied for Rotation are not close to orthogonal"
94 double u2u3 = ucolY.dot(ucolZ);
95 double f23 = std::fabs(u2u3);
97 std::cerr <<
"HepRotation::set() - "
98 <<
"col's Y and Z supplied for Rotation are not close to orthogonal"
102 Hep3Vector v1, v2, v3;
104 if ( (f12 <= f13) && (f12 <= f23) ) {
105 isRotation = setCols ( ucolX, ucolY, ucolZ, u1u2, v1, v2, v3 );
107 std::cerr <<
"HepRotation::set() - "
108 <<
"col's X Y and Z supplied form closer to a reflection than a Rotation "
109 <<
"\n col Z is set to col X cross col Y" << std::endl;
111 }
else if ( f13 <= f23 ) {
112 isRotation = setCols ( ucolZ, ucolX, ucolY, u1u3, v3, v1, v2 );
114 std::cerr <<
"HepRotation::set() - "
115 <<
"col's X Y and Z supplied form closer to a reflection than a Rotation "
116 <<
"\n col Y is set to col Z cross col X" << std::endl;
119 isRotation = setCols ( ucolY, ucolZ, ucolX, u2u3, v2, v3, v1 );
121 std::cerr <<
"HepRotation::set() - "
122 <<
"col's X Y and Z supplied form closer to a reflection than a Rotation "
123 <<
"\n col X is set to col Y cross col Z" << std::endl;
127 rxx = v1.x(); ryx = v1.y(); rzx = v1.z();
128 rxy = v2.x(); ryy = v2.y(); rzy = v2.z();
129 rxz = v3.x(); ryz = v3.y(); rzz = v3.z();
135 HepRotation::HepRotation (
const Hep3Vector & ccolX,
136 const Hep3Vector & ccolY,
137 const Hep3Vector & ccolZ )
139 set (ccolX, ccolY, ccolZ);
142 HepRotation & HepRotation::setRows(
const Hep3Vector & rrowX,
143 const Hep3Vector & rrowY,
144 const Hep3Vector & rrowZ ) {
145 set (rrowX, rrowY, rrowZ);
152 void HepRotation::rectify() {
163 double det = rxx * ryy * rzz +
170 std::cerr <<
"HepRotation::rectify() - "
171 <<
"Attempt to rectify a Rotation with determinant <= 0" << std::endl;
174 double di = 1.0 / det;
177 double xx1 = (ryy * rzz - ryz * rzy) * di;
178 double xy1 = (rzy * rxz - rzz * rxy) * di;
179 double xz1 = (rxy * ryz - rxz * ryy) * di;
180 double yx1 = (ryz * rzx - ryx * rzz) * di;
181 double yy1 = (rzz * rxx - rzx * rxz) * di;
182 double yz1 = (rxz * ryx - rxx * ryz) * di;
183 double zx1 = (ryx * rzy - ryy * rzx) * di;
184 double zy1 = (rzx * rxy - rzy * rxx) * di;
185 double zz1 = (rxx * ryy - rxy * ryx) * di;
188 rxx = .5*(rxx + xx1);
189 rxy = .5*(rxy + yx1);
190 rxz = .5*(rxz + zx1);
191 ryx = .5*(ryx + xy1);
192 ryy = .5*(ryy + yy1);
193 ryz = .5*(ryz + zy1);
194 rzx = .5*(rzx + xz1);
195 rzy = .5*(rzy + yz1);
196 rzz = .5*(rzz + zz1);
199 double del = delta();
200 Hep3Vector u = axis();
static const G4double tolerance