12 #pragma implementation
15 #include "CLHEP/Vector/Rotation.h"
16 #include "CLHEP/Units/PhysicalConstants.h"
27 HepRotation & HepRotation::set(
const Hep3Vector & aaxis,
double ddelta ) {
29 double sinDelta = std::sin(ddelta), cosDelta = std::cos(ddelta);
30 double oneMinusCosDelta = 1.0 - cosDelta;
32 Hep3Vector u = aaxis.unit();
38 rxx = oneMinusCosDelta * uX * uX + cosDelta;
39 rxy = oneMinusCosDelta * uX * uY - sinDelta * uZ;
40 rxz = oneMinusCosDelta * uX * uZ + sinDelta * uY;
42 ryx = oneMinusCosDelta * uY * uX + sinDelta * uZ;
43 ryy = oneMinusCosDelta * uY * uY + cosDelta;
44 ryz = oneMinusCosDelta * uY * uZ - sinDelta * uX;
46 rzx = oneMinusCosDelta * uZ * uX - sinDelta * uY;
47 rzy = oneMinusCosDelta * uZ * uY + sinDelta * uX;
48 rzz = oneMinusCosDelta * uZ * uZ + cosDelta;
54 HepRotation::HepRotation (
const Hep3Vector & aaxis,
double ddelta )
58 HepRotation & HepRotation::set(
const HepAxisAngle & ax ) {
59 return set ( ax.axis(), ax.delta() );
61 HepRotation::HepRotation (
const HepAxisAngle & ax )
63 set ( ax.axis(), ax.delta() );
66 double HepRotation::delta()
const {
68 double cosdelta = (rxx + ryy + rzz - 1.0) / 2.0;
71 }
else if (cosdelta < -1.0) {
74 return std::acos( cosdelta );
79 Hep3Vector HepRotation::axis ()
const {
84 double Uz = ryx - rxy;
85 double Uy = rxz - rzx;
86 double Ux = rzy - ryz;
88 if ( (Uz==0) && (Uy==0) && (Ux==0) ) {
90 return Hep3Vector(0,0,1);
92 return Hep3Vector(0,1,0);
94 return Hep3Vector(1,0,0);
97 return Hep3Vector( Ux, Uy, Uz ).unit();
102 HepAxisAngle HepRotation::axisAngle()
const {
104 return HepAxisAngle (axis(), delta());
109 void HepRotation::setAxis (
const Hep3Vector & aaxis) {
110 set ( aaxis, delta() );
113 void HepRotation::setDelta (
double ddelta) {
114 set ( axis(), ddelta );