| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <math.h> // for cos, sin |
| 10 |
|
| 11 |
void rotate2d(double **yvecs, /* ptr to list of y-vectors (rotated) */ |
| 12 |
int nmyvtxs, /* length of yvecs */ |
| 13 |
double theta /* angle to rotate by */ |
| 14 |
) |
| 15 |
{ |
| 16 |
double temp1; /* hold values for a while */ |
| 17 |
double c, s; /* cosine and sine of theta */ |
| 18 |
int i; /* loop counter */ |
| 19 |
|
| 20 |
s = sin(theta); |
| 21 |
c = cos(theta); |
| 22 |
|
| 23 |
for (i = 1; i <= nmyvtxs; i++) { |
| 24 |
temp1 = yvecs[1][i]; |
| 25 |
yvecs[1][i] = c * temp1 + s * yvecs[2][i]; |
| 26 |
yvecs[2][i] = -s * temp1 + c * yvecs[2][i]; |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
void rotate3d(double **yvecs, /* ptr to list of y-vectors (to be rotated) */ |
| 31 |
int nmyvtxs, /* length of yvecs */ |
| 32 |
double theta, double phi, double gamma2 /* rotational parameters */ |
| 33 |
) |
| 34 |
{ |
| 35 |
double temp1, temp2; /* hold values for a while */ |
| 36 |
double ctheta, stheta; /* cosine and sine of theta */ |
| 37 |
double cphi, sphi; /* cosine and sine of phi */ |
| 38 |
double cgamma, sgamma; /* cosine and sine of gamma */ |
| 39 |
double onemcg; /* 1.0 - cosine(gamma) */ |
| 40 |
double a1, a2, a3; /* rotation matrix entries */ |
| 41 |
double b1, b2, b3; /* rotation matrix entries */ |
| 42 |
double c1, c2, c3; /* rotation matrix entries */ |
| 43 |
int i; /* loop counter */ |
| 44 |
|
| 45 |
stheta = sin(theta); |
| 46 |
ctheta = cos(theta); |
| 47 |
sphi = sin(phi); |
| 48 |
cphi = cos(phi); |
| 49 |
sgamma = sin(gamma2); |
| 50 |
cgamma = cos(gamma2); |
| 51 |
|
| 52 |
onemcg = 1.0 - cgamma; |
| 53 |
|
| 54 |
a1 = cgamma + cphi * ctheta * onemcg * cphi * ctheta; |
| 55 |
a2 = sgamma * sphi + cphi * stheta * onemcg * cphi * ctheta; |
| 56 |
a3 = -sgamma * cphi * stheta + sphi * onemcg * cphi * ctheta; |
| 57 |
|
| 58 |
b1 = -sgamma * sphi + cphi * ctheta * onemcg * cphi * stheta; |
| 59 |
b2 = cgamma + cphi * stheta * onemcg * cphi * stheta; |
| 60 |
b3 = sgamma * cphi * ctheta + sphi * onemcg * cphi * stheta; |
| 61 |
|
| 62 |
c1 = sgamma * cphi * stheta + cphi * ctheta * onemcg * sphi; |
| 63 |
c2 = -sgamma * cphi * ctheta + cphi * stheta * onemcg * sphi; |
| 64 |
c3 = cgamma + sphi * onemcg * sphi; |
| 65 |
|
| 66 |
for (i = 1; i <= nmyvtxs; i++) { |
| 67 |
temp1 = yvecs[1][i]; |
| 68 |
temp2 = yvecs[2][i]; |
| 69 |
|
| 70 |
yvecs[1][i] = a1 * temp1 + b1 * temp2 + c1 * yvecs[3][i]; |
| 71 |
yvecs[2][i] = a2 * temp1 + b2 * temp2 + c2 * yvecs[3][i]; |
| 72 |
yvecs[3][i] = a3 * temp1 + b3 * temp2 + c3 * yvecs[3][i]; |
| 73 |
} |
| 74 |
} |