ATLAS Offline Software
Loading...
Searching...
No Matches
EulerAnglesHelpers.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5/*
6 * eigen_migration
7 * EulerAnglesHelpers.cpp
8 *
9 * Created on: Feb 11, 2014
10 * Author: rbianchi <Riccardo.Maria.Bianchi@cern.ch>
11 *
12 */
13
14#ifndef _GEOPRIMITIVES_EULERANGLESHELPERS_H
15#define _GEOPRIMITIVES_EULERANGLESHELPERS_H
16
18
20
21namespace Amg {
22
41inline Amg::Vector3D getPhiThetaPsi(Amg::RotationMatrix3D mat, int convention = 0)
42{
43 double phi;
44 double theta;
45 double psi;
46
47 Amg::Vector3D ea; // euler angles vector
48
54 // using Z-X-Z convention: (2,0,2) == "Z,X,Z"
55 if (convention == 0) {
56 ea = mat.eulerAngles(2, 0, 2); // (using Z-X-Z convention) // DEFAULT
57 }
58 // using Z-Y-Z convention: (2,1,2) == "Z,Y,Z"
59 else {
60 ea = mat.eulerAngles(2, 1, 2); // (using Z-Y-Z convention)
61 }
62
63 // convert the values from Eigen convention to CLHEP convention
65
66 phi = ea[0];
67 theta = ea[1];
68 psi = ea[2];
69
70 Amg::Vector3D phiThetaPsi_angles;
71 phiThetaPsi_angles(0) = phi;
72 phiThetaPsi_angles(1) = theta;
73 phiThetaPsi_angles(2) = psi;
74
75 return phiThetaPsi_angles;
76
77} // end of getPhiThetaPsi()
78
79
80
81
82
83
84
85/* Set the Phi angle of a rotation matrix,
86 * leaving Theta and Psi unaltered.
87 *
88 * Actually it returns a new rotation matrix
89 * built with the new Phi angle, and with the
90 * Theta and Psi angles taken from the original matrix.
91 *
92 * N.B.
93 * if "convention = 0" --> "Z-X-Z" convention ==> DEFAULT!!
94 * if "convention = 1" --> "Z-Y-Z" convention
95 *
96 * N.B.!!
97 * for normal usage, use the default notation (simply leave it empty, or use convention=0),
98 * or, alternatively, be sure to use the same convention in both setPhi() and getPhiThetaPsi().
99 *
100 *
101 */
102inline Amg::RotationMatrix3D setPhi(Amg::RotationMatrix3D mat, double angle, int convention = 0)
103{
104
105
106 Amg::Vector3D phi_theta_psi;
107
108
109 // using Z-X-Z convention: (2,0,2) == "Z,X,Z". ==> DEFAULT!
110 if (convention == 0) {
111 phi_theta_psi = getPhiThetaPsi(mat, 0); // using Z-X-Z ((2,0,2) convention // DEFAULT
112 }
113 else { // using Z-Y-Z convention: (2,1,2) == "Z,Y,Z"
114 phi_theta_psi = getPhiThetaPsi(mat, 1); // using Z-Y-Z ((2,1,2) convention
115 }
116
117 double phi = phi_theta_psi(0);
118 double theta = phi_theta_psi(1);
119 double psi = phi_theta_psi(2);
120
121
122 /*
123 * set a new Phi angle, from user's settings
124 */
125 phi = angle;
126
127 /*
128 * get Eigen Euler angles from CLEHP style Phi, Theta, Psi
129 */
130 Amg::Vector3D clhep_phiThetaPsi(phi, theta, psi); // a vector with CLHEP angles
131 Amg::Vector3D eigen_euler_angles;
132 // converting the CLHEP angles to Eigen angles
133 if (convention == 0) { // using Z-X-Z convention: (2,0,2) == "Z,X,Z". ==> DEFAULT!
134 eigen_euler_angles = convert_CLHEPPhiThetaPsi_to_EigenEulerAngles(clhep_phiThetaPsi, 0); // using Z-X-Z ((2,0,2) convention // DEFAULT
135 }
136 else { // using Z-Y-Z convention: (2,1,2) == "Z,Y,Z"
137 eigen_euler_angles = convert_CLHEPPhiThetaPsi_to_EigenEulerAngles(clhep_phiThetaPsi, 1); // using Z-Y-Z ((2,1,2) convention
138 }
139
140 /*
141 * create a new rotation matrix from AngleAxis
142 *
143 * N.B.!!
144 * to match CLHEP results,
145 * we have to invert the order of the rotation operations,
146 * compared to the order in CLHEP.
147 * The matrix here below is equal to:
148 * ---
149 * CLHEP::HepRotation localRot;
150 * localRot.rotateZ(angC);
151 * localRot.rotateY(angB);
152 * localRot.rotateZ(angA);
153 * ---
154 *
155 */
156
157 if (convention == 0) { // using Z-X-Z convention: (2,0,2) == "Z,X,Z". ==> DEFAULT!
158 mat = Amg::AngleAxis3D(eigen_euler_angles(0), Amg::Vector3D::UnitZ())
159 * Amg::AngleAxis3D(eigen_euler_angles(1), Amg::Vector3D::UnitX())
160 * Amg::AngleAxis3D(eigen_euler_angles(2), Amg::Vector3D::UnitZ());
161 }
162 else { // using Z-Y-Z convention: (2,1,2) == "Z,Y,Z"
163 mat = Amg::AngleAxis3D(eigen_euler_angles(0), Amg::Vector3D::UnitZ())
164 * Amg::AngleAxis3D(eigen_euler_angles(1), Amg::Vector3D::UnitY())
165 * Amg::AngleAxis3D(eigen_euler_angles(2), Amg::Vector3D::UnitZ());
166 }
167
168 return mat;
169
170} // end of SetPhi()
171
172
173
174
175} // end of namespace Amg
176
177
178#endif
179
Scalar phi() const
phi method
Scalar theta() const
theta method
Definition of ATLAS Math & Geometry primitives (Amg)
Eigen::AngleAxisd AngleAxis3D
Amg::Vector3D getPhiThetaPsi(Amg::RotationMatrix3D mat, int convention=0)
Get the equivalents to CLHEP Phi, Theta, Psi Euler angles.
Amg::Vector3D convert_EigenEulerAngles_to_CLHEPPhiThetaPsi(Amg::Vector3D eigen_angles, int convention=0)
Convert Eigen euler angles to CLEHP Phi,Theta,Psi angles.
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Amg::Vector3D convert_CLHEPPhiThetaPsi_to_EigenEulerAngles(Amg::Vector3D clhep_angles, int convention=0)
Convert CLEHP Phi,Theta,Psi angles to Eigen euler angles using Z-X-Z convention.
Amg::RotationMatrix3D setPhi(Amg::RotationMatrix3D mat, double angle, int convention=0)
double angle(const Amg::Vector3D &v1, const Amg::Vector3D &v2)
calculates the opening angle between two vectors
Eigen::Matrix< double, 3, 1 > Vector3D