| 183 |
|
} |
| 184 |
|
} |
| 185 |
|
} |
| 186 |
+ |
|
| 187 |
+ |
void getRandomRot( double rot[3][3] ){ |
| 188 |
+ |
|
| 189 |
+ |
double theta, phi, psi; |
| 190 |
+ |
double cosTheta; |
| 191 |
+ |
|
| 192 |
+ |
// select random phi, psi, and cosTheta |
| 193 |
+ |
|
| 194 |
+ |
phi = 2.0 * M_PI * drand48(); |
| 195 |
+ |
psi = 2.0 * M_PI * drand48(); |
| 196 |
+ |
cosTheta = (2.0 * drand48()) - 1.0; // sample cos -1 to 1 |
| 197 |
+ |
|
| 198 |
+ |
theta = acos( cosTheta ); |
| 199 |
+ |
|
| 200 |
+ |
getEulerRot( theta, phi, psi, rot ); |
| 201 |
+ |
} |
| 202 |
+ |
|
| 203 |
+ |
|
| 204 |
+ |
void getEulerRot( double theta, double phi, double psi, double rot[3][3] ){ |
| 205 |
+ |
|
| 206 |
+ |
rot[0][0] = (cos(phi) * cos(psi)) - (sin(phi) * cos(theta) * sin(psi)); |
| 207 |
+ |
rot[0][1] = (sin(phi) * cos(psi)) + (cos(phi) * cos(theta) * sin(psi)); |
| 208 |
+ |
rot[0][2] = sin(theta) * sin(psi); |
| 209 |
+ |
|
| 210 |
+ |
rot[1][0] = -(cos(phi) * sin(psi)) - (sin(phi) * cos(theta) * cos(psi)); |
| 211 |
+ |
rot[1][1] = -(sin(phi) * sin(psi)) + (cos(phi) * cos(theta) * cos(psi)); |
| 212 |
+ |
rot[1][2] = sin(theta) * cos(psi); |
| 213 |
+ |
|
| 214 |
+ |
rot[2][0] = sin(phi) * sin(theta); |
| 215 |
+ |
rot[2][1] = -cos(phi) * sin(theta); |
| 216 |
+ |
rot[2][2] = cos(theta); |
| 217 |
+ |
} |
| 218 |
+ |
|
| 219 |
+ |
|
| 220 |
+ |
void getUnitRot( double u[3], double rot[3][3] ){ |
| 221 |
+ |
|
| 222 |
+ |
double theta, phi, psi; |
| 223 |
+ |
|
| 224 |
+ |
theta = acos(u[2]); |
| 225 |
+ |
phi = atan(u[1] / u[0]); |
| 226 |
+ |
psi = 0.0; |
| 227 |
+ |
|
| 228 |
+ |
getEulerRot( theta, phi, psi, rot ); |
| 229 |
+ |
} |
| 230 |
+ |
|
| 231 |
+ |
|