| Bsoft 2.0.5 Bernard's software package

Euler.h
Go to the documentation of this file.
1
9 #ifndef _Euler_
10 #define _Euler_
11
12 #include "Vector3.h"
13 #include "Matrix3.h"
14 #include "Quaternion.h"
15 #include "View.h"
16 #include "utilities.h"
17
18 /************************************************************************
19 @Object: class Euler
20 @Description:
21 Euler angle parameter structure.
22 @Features:
23 Three Euler angles:
24 psi: rotation around z
25 theta: rotation around y
26 phi: rotation around z
27 *************************************************************************/
28 class Euler {
29 private:
30 double data[3];
31 void check() {
32 for ( int i = 0; i<3; i++ ) data[i] = angle_set_negPI_to_PI(data[i]);
33 }
34 public:
35 Euler() { for ( int i = 0; i<3; i++ ) data[i] = 0; }
36 Euler(const Euler& e) { for ( int i = 0; i<3; i++ ) data[i] = e.data[i]; }
37 Euler(const double psi, const double theta, const double phi) {
38 data[0] = psi; data[1] = theta; data[2] = phi;
39 }
40 Euler(View& v) {
41 data[1] = acos(v[2]);
42 if ( fabs(v[0]) > 1e-6 || fabs(v[1]) > 1e-6 )
43 data[2] = atan2(v[1], v[0]);
44 data[0] = angle_set_negPI_to_PI(v.angle() - data[2]);
45 if ( fabs(data[0]) < TRIGPRECISION ) data[0] = 0.0L;
46 }
47 Euler(Matrix3& m) {
48 View v = View(m);
49 *this = Euler(v);
50 }
51 Euler operator=(const Euler& e) {
52 for ( int i = 0; i<3; i++ ) data[i] = e.data[i];
53 return *this;
54 }
55 double& operator[](int i) { if ( i < 0 ) i = 0; if ( i > 2 ) i = 2; return data[i]; }
56 double psi() { return data[0]; }
57 double theta() { return data[1]; }
58 double phi() { return data[2]; }
59 void psi(const double d) { data[0] = d; }
60 void theta(const double d) { data[1] = d; }
61 void phi(const double d) { data[2] = d; }
62 View view() {
63 View v(cos(data[2])*sin(data[1]), sin(data[2])*sin(data[1]),
64 cos(data[1]), angle_set_negPI_to_PI(data[0] + data[2]));
65 return v;
66 }
67 Matrix3 matrix() {
68 double phi_2 = data[2]/2.0L;
69 double theta_2 = data[1]/2.0L;
70 double psi_2 = data[0]/2.0L;
71 Quaternion q1(cos(phi_2), 0, 0, sin(phi_2));
72 Quaternion q2(cos(theta_2), 0, sin(theta_2), 0);
73 Quaternion q3(cos(psi_2), 0, 0, sin(psi_2));
74 Quaternion q = q1 * q2 * q3;
75 return Matrix3(q);
76 }
77 } ;
78 /*
79 ostream& operator<<(ostream& output, Euler& euler) {
80 output.setf(ios::fixed, ios::floatfield);
81 output.precision(4);
82 output << "{" << euler.psi() << "," << euler.theta() << "," << euler.phi() << "}" << endl;
83 return output;
84 }
85 */
86 #endif
87
88
89
Euler::matrix
Matrix3 matrix()
Definition: Euler.h:67
Euler
Definition: Euler.h:28
utilities.h
Header file for general utilities.
angle_set_negPI_to_PI
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
Definition: utilities.cpp:594
Matrix3
Definition: Matrix3.h:17
Quaternion
Definition: Quaternion.h:25
Euler::Euler
Euler()
Definition: Euler.h:35
TRIGPRECISION
#define TRIGPRECISION
Definition: utilities.h:47
Euler::Euler
Euler(const Euler &e)
Definition: Euler.h:36
Matrix3.h
3x3 Matrix manipulation functions
Euler::psi
double psi()
Definition: Euler.h:56
Euler::phi
double phi()
Definition: Euler.h:58
Euler::theta
void theta(const double d)
Definition: Euler.h:60
Euler::operator=
Euler operator=(const Euler &e)
Definition: Euler.h:51
Euler::psi
void psi(const double d)
Definition: Euler.h:59
Quaternion.h
Class for quaternions.
Euler::Euler
Euler(View &v)
Definition: Euler.h:40
Euler::theta
double theta()
Definition: Euler.h:57
Euler::operator[]
double & operator[](int i)
Definition: Euler.h:55
Euler::Euler
Euler(const double psi, const double theta, const double phi)
Definition: Euler.h:37
View::angle
double angle()
Definition: View.h:95
Vector3.h
Class for 3-value vectors.
View
Definition: View.h:26
Euler::view
View view()
Definition: Euler.h:62
Euler::phi
void phi(const double d)
Definition: Euler.h:61
View.h
View object.
Euler::Euler
Euler(Matrix3 &m)
Definition: Euler.h:47