-
Notifications
You must be signed in to change notification settings - Fork 6
/
ptm_quat.h
176 lines (157 loc) · 12.2 KB
/
ptm_quat.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*Copyright (c) 2016 PM Larsen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef PTM_QUAT_H
#define PTM_QUAT_H
namespace ptm {
const double generator_cubic[24][4] = {
{ 1, 0, 0, 0 },
{ sqrt(2)/2, sqrt(2)/2, 0, 0 },
{ sqrt(2)/2, 0, sqrt(2)/2, 0 },
{ sqrt(2)/2, 0, 0, sqrt(2)/2 },
{ sqrt(2)/2, 0, 0, -sqrt(2)/2 },
{ sqrt(2)/2, 0, -sqrt(2)/2, 0 },
{ sqrt(2)/2, -sqrt(2)/2, -0, -0 },
{ 0.5, 0.5, 0.5, 0.5 },
{ 0.5, 0.5, 0.5, -0.5 },
{ 0.5, 0.5, -0.5, 0.5 },
{ 0.5, 0.5, -0.5, -0.5 },
{ 0.5, -0.5, 0.5, 0.5 },
{ 0.5, -0.5, 0.5, -0.5 },
{ 0.5, -0.5, -0.5, 0.5 },
{ 0.5, -0.5, -0.5, -0.5 },
{ 0, 1, 0, 0 },
{ 0, sqrt(2)/2, sqrt(2)/2, 0 },
{ 0, sqrt(2)/2, 0, sqrt(2)/2 },
{ 0, sqrt(2)/2, 0, -sqrt(2)/2 },
{ 0, sqrt(2)/2, -sqrt(2)/2, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, sqrt(2)/2, sqrt(2)/2 },
{ 0, 0, sqrt(2)/2, -sqrt(2)/2 },
{ 0, 0, 0, 1 },
};
const double generator_diamond_cubic[12][4] = {
{ 1, 0, 0, 0 },
{ 0.5, 0.5, 0.5, 0.5 },
{ 0.5, 0.5, 0.5, -0.5 },
{ 0.5, 0.5, -0.5, 0.5 },
{ 0.5, 0.5, -0.5, -0.5 },
{ 0.5, -0.5, 0.5, 0.5 },
{ 0.5, -0.5, 0.5, -0.5 },
{ 0.5, -0.5, -0.5, 0.5 },
{ 0.5, -0.5, -0.5, -0.5 },
{ 0, 1, 0, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, 0, 1 },
};
const double generator_hcp[6][4] = {
{ 1, 0, 0, 0 },
{ 0.5, 0, 0, sqrt(3)/2 },
{ 0.5, 0, 0, -sqrt(3)/2 },
{ 0, sqrt(3)/2, 0.5, 0 },
{ 0, sqrt(3)/2, -0.5, 0 },
{ 0, 0, 1, 0 },
};
const double generator_hcp_conventional[12][4] = {
{ 1, 0, 0, 0 },
{ sqrt(3)/2, 0, 0, 0.5 },
{ sqrt(3)/2, 0, 0, -0.5 },
{ 0.5, 0, 0, sqrt(3)/2 },
{ 0.5, 0, 0, -sqrt(3)/2 },
{ 0, 1, 0, 0 },
{ 0, sqrt(3)/2, 0.5, 0 },
{ 0, sqrt(3)/2, -0.5, 0 },
{ 0, 0.5, sqrt(3)/2, 0 },
{ 0, 0.5, -sqrt(3)/2, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, 0, 1 },
};
const double generator_diamond_hexagonal[3][4] = {
{ 1, 0, 0, 0 },
{ 0.5, 0, 0, sqrt(3)/2 },
{ 0.5, 0, 0, -sqrt(3)/2 },
};
const double generator_icosahedral[60][4] = {
{ 1, 0, 0, 0 },
{ (1+sqrt(5))/4, 0.5, sqrt(25-10*sqrt(5))/10, sqrt(50-10*sqrt(5))/20 },
{ (1+sqrt(5))/4, 0.5, -sqrt(25-10*sqrt(5))/10, -sqrt(50-10*sqrt(5))/20 },
{ (1+sqrt(5))/4, 1/(1+sqrt(5)), sqrt(10*sqrt(5)+50)/20, -sqrt(50-10*sqrt(5))/20 },
{ (1+sqrt(5))/4, 1/(1+sqrt(5)), -sqrt(10*sqrt(5)+50)/20, sqrt(50-10*sqrt(5))/20 },
{ (1+sqrt(5))/4, 0, sqrt(50-10*sqrt(5))/10, sqrt(50-10*sqrt(5))/20 },
{ (1+sqrt(5))/4, 0, 0, sqrt(5./8-sqrt(5)/8) },
{ (1+sqrt(5))/4, 0, 0, -sqrt(5./8-sqrt(5)/8) },
{ (1+sqrt(5))/4, 0, -sqrt(50-10*sqrt(5))/10, -sqrt(50-10*sqrt(5))/20 },
{ (1+sqrt(5))/4, -1/(1+sqrt(5)), sqrt(10*sqrt(5)+50)/20, -sqrt(50-10*sqrt(5))/20 },
{ (1+sqrt(5))/4, -1/(1+sqrt(5)), -sqrt(10*sqrt(5)+50)/20, sqrt(50-10*sqrt(5))/20 },
{ (1+sqrt(5))/4, -0.5, sqrt(25-10*sqrt(5))/10, sqrt(50-10*sqrt(5))/20 },
{ (1+sqrt(5))/4, -0.5, -sqrt(25-10*sqrt(5))/10, -sqrt(50-10*sqrt(5))/20 },
{ 0.5, (1+sqrt(5))/4, sqrt(50-10*sqrt(5))/20, -sqrt(25-10*sqrt(5))/10 },
{ 0.5, (1+sqrt(5))/4, -sqrt(50-10*sqrt(5))/20, sqrt(25-10*sqrt(5))/10 },
{ 0.5, 0.5, sqrt((5+2*sqrt(5))/20), sqrt(25-10*sqrt(5))/10 },
{ 0.5, 0.5, sqrt(25-10*sqrt(5))/10, -sqrt((5+2*sqrt(5))/20) },
{ 0.5, 0.5, -sqrt(25-10*sqrt(5))/10, sqrt((5+2*sqrt(5))/20) },
{ 0.5, 0.5, -sqrt((5+2*sqrt(5))/20), -sqrt(25-10*sqrt(5))/10 },
{ 0.5, 1/(1+sqrt(5)), sqrt(10*sqrt(5)+50)/20, sqrt((5+2*sqrt(5))/20) },
{ 0.5, 1/(1+sqrt(5)), -sqrt(10*sqrt(5)+50)/20, -sqrt((5+2*sqrt(5))/20) },
{ 0.5, 0, sqrt((5+sqrt(5))/10), -sqrt(25-10*sqrt(5))/10 },
{ 0.5, 0, sqrt(50-10*sqrt(5))/10, -sqrt((5+2*sqrt(5))/20) },
{ 0.5, 0, -sqrt(50-10*sqrt(5))/10, sqrt((5+2*sqrt(5))/20) },
{ 0.5, 0, -sqrt((5+sqrt(5))/10), sqrt(25-10*sqrt(5))/10 },
{ 0.5, -1/(1+sqrt(5)), sqrt(10*sqrt(5)+50)/20, sqrt((5+2*sqrt(5))/20) },
{ 0.5, -1/(1+sqrt(5)), -sqrt(10*sqrt(5)+50)/20, -sqrt((5+2*sqrt(5))/20) },
{ 0.5, -0.5, sqrt((5+2*sqrt(5))/20), sqrt(25-10*sqrt(5))/10 },
{ 0.5, -0.5, sqrt(25-10*sqrt(5))/10, -sqrt((5+2*sqrt(5))/20) },
{ 0.5, -0.5, -sqrt(25-10*sqrt(5))/10, sqrt((5+2*sqrt(5))/20) },
{ 0.5, -0.5, -sqrt((5+2*sqrt(5))/20), -sqrt(25-10*sqrt(5))/10 },
{ 0.5, -(1+sqrt(5))/4, sqrt(50-10*sqrt(5))/20, -sqrt(25-10*sqrt(5))/10 },
{ 0.5, -(1+sqrt(5))/4, -sqrt(50-10*sqrt(5))/20, sqrt(25-10*sqrt(5))/10 },
{ 1/(1+sqrt(5)), (1+sqrt(5))/4, sqrt(50-10*sqrt(5))/20, sqrt(10*sqrt(5)+50)/20 },
{ 1/(1+sqrt(5)), (1+sqrt(5))/4, -sqrt(50-10*sqrt(5))/20, -sqrt(10*sqrt(5)+50)/20 },
{ 1/(1+sqrt(5)), 0.5, sqrt((5+2*sqrt(5))/20), -sqrt(10*sqrt(5)+50)/20 },
{ 1/(1+sqrt(5)), 0.5, -sqrt((5+2*sqrt(5))/20), sqrt(10*sqrt(5)+50)/20 },
{ 1/(1+sqrt(5)), 0, sqrt((5+sqrt(5))/10), sqrt(10*sqrt(5)+50)/20 },
{ 1/(1+sqrt(5)), 0, 0, sqrt(1-1/(2*sqrt(5)+6)) },
{ 1/(1+sqrt(5)), 0, 0, -sqrt(1-1/(2*sqrt(5)+6)) },
{ 1/(1+sqrt(5)), 0, -sqrt((5+sqrt(5))/10), -sqrt(10*sqrt(5)+50)/20 },
{ 1/(1+sqrt(5)), -0.5, sqrt((5+2*sqrt(5))/20), -sqrt(10*sqrt(5)+50)/20 },
{ 1/(1+sqrt(5)), -0.5, -sqrt((5+2*sqrt(5))/20), sqrt(10*sqrt(5)+50)/20 },
{ 1/(1+sqrt(5)), -(1+sqrt(5))/4, sqrt(50-10*sqrt(5))/20, sqrt(10*sqrt(5)+50)/20 },
{ 1/(1+sqrt(5)), -(1+sqrt(5))/4, -sqrt(50-10*sqrt(5))/20, -sqrt(10*sqrt(5)+50)/20 },
{ 0, 1, 0, 0 },
{ 0, (1+sqrt(5))/4, sqrt(5./8-sqrt(5)/8), 0 },
{ 0, (1+sqrt(5))/4, sqrt(50-10*sqrt(5))/20, -sqrt(50-10*sqrt(5))/10 },
{ 0, (1+sqrt(5))/4, -sqrt(50-10*sqrt(5))/20, sqrt(50-10*sqrt(5))/10 },
{ 0, (1+sqrt(5))/4, -sqrt(5./8-sqrt(5)/8), 0 },
{ 0, 0.5, sqrt((5+2*sqrt(5))/20), sqrt(50-10*sqrt(5))/10 },
{ 0, 0.5, sqrt(25-10*sqrt(5))/10, sqrt((5+sqrt(5))/10) },
{ 0, 0.5, -sqrt(25-10*sqrt(5))/10, -sqrt((5+sqrt(5))/10) },
{ 0, 0.5, -sqrt((5+2*sqrt(5))/20), -sqrt(50-10*sqrt(5))/10 },
{ 0, 1/(1+sqrt(5)), sqrt(1-1/(2*sqrt(5)+6)), 0 },
{ 0, 1/(1+sqrt(5)), sqrt(10*sqrt(5)+50)/20, -sqrt((5+sqrt(5))/10) },
{ 0, 1/(1+sqrt(5)), -sqrt(10*sqrt(5)+50)/20, sqrt((5+sqrt(5))/10) },
{ 0, 1/(1+sqrt(5)), -sqrt(1-1/(2*sqrt(5)+6)), 0 },
{ 0, 0, sqrt((5+sqrt(5))/10), -sqrt(50-10*sqrt(5))/10 },
{ 0, 0, sqrt(50-10*sqrt(5))/10, sqrt((5+sqrt(5))/10) },
};
int rotate_quaternion_into_cubic_fundamental_zone(double* q);
int rotate_quaternion_into_diamond_cubic_fundamental_zone(double* q);
int rotate_quaternion_into_icosahedral_fundamental_zone(double* q);
int rotate_quaternion_into_hcp_fundamental_zone(double* q);
int rotate_quaternion_into_hcp_conventional_fundamental_zone(double* q);
int rotate_quaternion_into_diamond_hexagonal_fundamental_zone(double* q);
void quat_rot(double* r, double* a, double* b);
void normalize_quaternion(double* q);
void quaternion_to_rotation_matrix(double* q, double* U);
void rotation_matrix_to_quaternion(double* u, double* q);
double quat_dot(double* a, double* b);
double quat_misorientation(double* q1, double* q2);
int map_quaternion_cubic(double* q, int i);
int map_quaternion_diamond_cubic(double* q, int i);
int map_quaternion_icosahedral(double* q, int i);
int map_quaternion_hcp(double* q, int i);
int map_quaternion_hcp_conventional(double* q, int i);
int map_quaternion_diamond_hexagonal(double* q, int i);
}
#endif