1 |
#include <cmath> |
2 |
|
3 |
#include "Atom.hpp" |
4 |
|
5 |
void DirectionalAtom::setA( double the_A[3][3] ){ |
6 |
|
7 |
Axx = the_A[0][0]; Axy = the_A[0][1]; Axz = the_A[0][2]; |
8 |
Ayx = the_A[1][0]; Ayy = the_A[1][1]; Ayz = the_A[1][2]; |
9 |
Azx = the_A[2][0]; Azy = the_A[2][1]; Azz = the_A[2][2]; |
10 |
} |
11 |
|
12 |
void DirectionalAtom::setI( double the_I[3][3] ){ |
13 |
|
14 |
Ixx = the_I[0][0]; Ixy = the_I[0][1]; Ixz = the_I[0][2]; |
15 |
Iyx = the_I[1][0]; Iyy = the_I[1][1]; Iyz = the_I[1][2]; |
16 |
Izx = the_I[2][0]; Izy = the_I[2][1]; Izz = the_I[2][2]; |
17 |
} |
18 |
|
19 |
void DirectionalAtom::setQ( double the_q[4] ){ |
20 |
|
21 |
double q0Sqr, q1Sqr, q2Sqr, q3Sqr; |
22 |
|
23 |
q0Sqr = the_q[0] * the_q[0]; |
24 |
q1Sqr = the_q[1] * the_q[1]; |
25 |
q2Sqr = the_q[2] * the_q[2]; |
26 |
q3Sqr = the_q[3] * the_q[3]; |
27 |
|
28 |
|
29 |
Axx = q0Sqr + q1Sqr - q2Sqr - q3Sqr; |
30 |
Axy = 2.0 * ( the_q[1] * the_q[2] + the_q[0] * the_q[3] ); |
31 |
Axz = 2.0 * ( the_q[1] * the_q[3] - the_q[0] * the_q[2] ); |
32 |
|
33 |
Ayx = 2.0 * ( the_q[1] * the_q[2] - the_q[0] * the_q[3] ); |
34 |
Ayy = q0Sqr - q1Sqr + q2Sqr - q3Sqr; |
35 |
Ayz = 2.0 * ( the_q[2] * the_q[3] + the_q[0] * the_q[1] ); |
36 |
|
37 |
Azx = 2.0 * ( the_q[1] * the_q[3] + the_q[0] * the_q[2] ); |
38 |
Azy = 2.0 * ( the_q[2] * the_q[3] - the_q[0] * the_q[1] ); |
39 |
Azz = q0Sqr - q1Sqr -q2Sqr +q3Sqr; |
40 |
} |
41 |
|
42 |
void DirectionalAtom::getU( double the_u[3] ){ |
43 |
|
44 |
the_u[0] = sux; |
45 |
the_u[1] = suy; |
46 |
the_u[2] = suz; |
47 |
|
48 |
this->body2Lab( the_u ); |
49 |
} |
50 |
|
51 |
void DirectionalAtom::getQ( double q[4] ){ |
52 |
|
53 |
double t, s; |
54 |
double ad1, ad2, ad3; |
55 |
|
56 |
t = Axx + Ayy + Azz + 1.0; |
57 |
if( t > 0.0 ){ |
58 |
|
59 |
s = 0.5 / sqrt( t ); |
60 |
q[0] = 0.25 / s; |
61 |
q[1] = (Ayz - Azy) * s; |
62 |
q[2] = (Azx - Axz) * s; |
63 |
q[3] = (Axy - Ayx) * s; |
64 |
} |
65 |
else{ |
66 |
|
67 |
ad1 = fabs( Axx ); |
68 |
ad2 = fabs( Ayy ); |
69 |
ad3 = fabs( Azz ); |
70 |
|
71 |
if( ad1 >= ad2 && ad1 >= ad3 ){ |
72 |
|
73 |
s = 2.0 * sqrt( 1.0 + Axx - Ayy - Azz ); |
74 |
q[0] = (Ayz + Azy) / s; |
75 |
q[1] = 0.5 / s; |
76 |
q[2] = (Axy + Ayx) / s; |
77 |
q[3] = (Axz + Azx) / s; |
78 |
} |
79 |
else if( ad2 >= ad1 && ad2 >= ad3 ){ |
80 |
|
81 |
s = sqrt( 1.0 + Ayy - Axx - Azz ) * 2.0; |
82 |
q[0] = (Axz + Azx) / s; |
83 |
q[1] = (Axy + Ayx) / s; |
84 |
q[2] = 0.5 / s; |
85 |
q[3] = (Ayz + Azy) / s; |
86 |
} |
87 |
else{ |
88 |
|
89 |
s = sqrt( 1.0 + Azz - Axx - Ayy ) * 2.0; |
90 |
q[0] = (Axy + Ayx) / s; |
91 |
q[1] = (Axz + Azx) / s; |
92 |
q[2] = (Ayz + Azy) / s; |
93 |
q[3] = 0.5 / s; |
94 |
} |
95 |
} |
96 |
} |
97 |
|
98 |
|
99 |
void DirectionalAtom::setEuler( double phi, double theta, double psi ){ |
100 |
|
101 |
Axx = (cos(phi) * cos(psi)) - (sin(phi) * cos(theta) * sin(psi)); |
102 |
Axy = (sin(phi) * cos(psi)) + (cos(phi) * cos(theta) * sin(psi)); |
103 |
Axz = sin(theta) * sin(psi); |
104 |
|
105 |
Ayx = -(cos(phi) * sin(psi)) - (sin(phi) * cos(theta) * cos(psi)); |
106 |
Ayy = -(sin(phi) * sin(psi)) + (cos(phi) * cos(theta) * cos(psi)); |
107 |
Ayz = sin(theta) * cos(psi); |
108 |
|
109 |
Azx = sin(phi) * sin(theta); |
110 |
Azy = -cos(phi) * sin(theta); |
111 |
Azz = cos(theta); |
112 |
} |
113 |
|
114 |
|
115 |
void DirectionalAtom::lab2Body( double r[3] ){ |
116 |
|
117 |
double rl[3]; // the lab frame vector |
118 |
|
119 |
rl[0] = r[0]; |
120 |
rl[1] = r[1]; |
121 |
rl[2] = r[2]; |
122 |
|
123 |
r[0] = (Axx * rl[0]) + (Axy * rl[1]) + (Axz * rl[2]); |
124 |
r[1] = (Ayx * rl[0]) + (Ayy * rl[1]) + (Ayz * rl[2]); |
125 |
r[2] = (Azx * rl[0]) + (Azy * rl[1]) + (Azz * rl[2]); |
126 |
} |
127 |
|
128 |
void DirectionalAtom::body2Lab( double r[3] ){ |
129 |
|
130 |
double rb[3]; // the body frame vector |
131 |
|
132 |
rb[0] = r[0]; |
133 |
rb[1] = r[1]; |
134 |
rb[2] = r[2]; |
135 |
|
136 |
r[0] = (Axx * rb[0]) + (Ayx * rb[1]) + (Azx * rb[2]); |
137 |
r[1] = (Axy * rb[0]) + (Ayy * rb[1]) + (Azy * rb[2]); |
138 |
r[2] = (Axz * rb[0]) + (Ayz * rb[1]) + (Azz * rb[2]); |
139 |
} |
140 |
|