CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
RotationA.cc
Go to the documentation of this file.
1// -*- C++ -*-
2// ---------------------------------------------------------------------------
3//
4// This file is a part of the CLHEP - a Class Library for High Energy Physics.
5//
6// This is the implementation of those methods of the HepRotation class which
7// were introduced when ZOOM PhysicsVectors was merged in, and which involve
8// the angle/axis representation of a Rotation.
9//
10
11#include "CLHEP/Vector/defs.h"
12#include "CLHEP/Vector/Rotation.h"
13#include "CLHEP/Units/PhysicalConstants.h"
14
15#include <iostream>
16#include <cmath>
17
18namespace CLHEP {
19
20// ---------- Constructors and Assignment:
21
22// axis and angle
23
24HepRotation & HepRotation::set( const Hep3Vector & aaxis, double ddelta ) {
25
26 double sinDelta = std::sin(ddelta), cosDelta = std::cos(ddelta);
27 double oneMinusCosDelta = 1.0 - cosDelta;
28
29 Hep3Vector u = aaxis.unit();
30
31 double uX = u.getX();
32 double uY = u.getY();
33 double uZ = u.getZ();
34
35 rxx = oneMinusCosDelta * uX * uX + cosDelta;
36 rxy = oneMinusCosDelta * uX * uY - sinDelta * uZ;
37 rxz = oneMinusCosDelta * uX * uZ + sinDelta * uY;
38
39 ryx = oneMinusCosDelta * uY * uX + sinDelta * uZ;
40 ryy = oneMinusCosDelta * uY * uY + cosDelta;
41 ryz = oneMinusCosDelta * uY * uZ - sinDelta * uX;
42
43 rzx = oneMinusCosDelta * uZ * uX - sinDelta * uY;
44 rzy = oneMinusCosDelta * uZ * uY + sinDelta * uX;
45 rzz = oneMinusCosDelta * uZ * uZ + cosDelta;
46
47 return *this;
48
49} // HepRotation::set(axis, delta)
50
51HepRotation::HepRotation ( const Hep3Vector & aaxis, double ddelta )
52{
53 set( aaxis, ddelta );
54}
56 return set ( ax.axis(), ax.delta() );
57}
59{
60 set ( ax.axis(), ax.delta() );
61}
62
63double HepRotation::delta() const {
64
65 double cosdelta = (rxx + ryy + rzz - 1.0) / 2.0;
66 if (cosdelta > 1.0) {
67 return 0;
68 } else if (cosdelta < -1.0) {
69 return CLHEP::pi;
70 } else {
71 return std::acos( cosdelta ); // Already safe due to the cosdelta > 1 check
72 }
73
74} // delta()
75
77
78 const double eps = 1e-15;
79
80 double Ux = rzy - ryz;
81 double Uy = rxz - rzx;
82 double Uz = ryx - rxy;
83 if (std::abs(Ux) < eps && std::abs(Uy) < eps && std::abs(Uz) < eps) {
84
85 double cosdelta = (rxx + ryy + rzz - 1.0) / 2.0;
86 if (cosdelta > 0.0) return Hep3Vector(0,0,1); // angle = 0, any axis is good
87
88 double xxt = (rxx + 1)/2;
89 double yyt = (ryy + 1)/2;
90 double zzt = (rzz + 1)/2;
91 double xyt = (rxy + ryx)/4;
92 double xzt = (rxz + rzx)/4;
93 double yzt = (ryz + rzy)/4;
94 double x, y, z;
95
96 if (xxt > ryy && xxt > rzz) {
97 x = std::sqrt(xxt);
98 if (rzy - ryz < 0) x = -x;
99 y = xyt/x;
100 z = xzt/x;
101 return Hep3Vector( x, y, z ).unit();
102 } else if (yyt > zzt) {
103 y = std::sqrt(yyt);
104 if (rxz - rzx < 0) y = -y;
105 x = xyt/y;
106 z = yzt/y;
107 return Hep3Vector( x, y, z ).unit();
108 } else {
109 z = std::sqrt(zzt);
110 if (ryx - rxy < 0) z = -z;
111 x = xzt/z;
112 y = yzt/z;
113 return Hep3Vector( x, y, z ).unit();
114 }
115 } else {
116 return Hep3Vector( Ux, Uy, Uz ).unit();
117 }
118
119} // axis()
120
122
123 return HepAxisAngle (axis(), delta());
124
125} // axisAngle()
126
127
128void HepRotation::setAxis (const Hep3Vector & aaxis) {
129 set ( aaxis, delta() );
130}
131
132void HepRotation::setDelta (double ddelta) {
133 set ( axis(), ddelta );
134}
135
136} // namespace CLHEP
Hep3Vector unit() const
double getZ() const
double getX() const
double getY() const
double delta() const
Hep3Vector axis() const
HepAxisAngle axisAngle() const
Definition: RotationA.cc:121
Hep3Vector axis() const
Definition: RotationA.cc:76
double delta() const
Definition: RotationA.cc:63
HepRotation & set(const Hep3Vector &axis, double delta)
Definition: RotationA.cc:24
void setDelta(double delta)
Definition: RotationA.cc:132
void setAxis(const Hep3Vector &axis)
Definition: RotationA.cc:128