1 /* This software was developed by Bruce Hendrickson and Robert Leland   *
2  * at Sandia National Laboratories under US Department of Energy        *
3  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
4 
5 #include	<stdio.h>
6 #include	<math.h>
7 #include	"defs.h"
8 
9 
rotate2d(yvecs,nmyvtxs,theta)10 void      rotate2d(yvecs, nmyvtxs, theta)
11 double  **yvecs;		/* ptr to list of y-vectors (rotated) */
12 int       nmyvtxs;		/* length of yvecs */
13 double    theta;		/* angle to rotate by */
14 {
15     double    temp1;		/* hold values for a while */
16     double    c, s;		/* cosine and sine of theta */
17     int       i;		/* loop counter */
18 
19     s = sin(theta);
20     c = cos(theta);
21 
22     for (i = 1; i <= nmyvtxs; i++) {
23 	temp1 = yvecs[1][i];
24 	yvecs[1][i] = c * temp1 + s * yvecs[2][i];
25 	yvecs[2][i] = -s * temp1 + c * yvecs[2][i];
26     }
27 }
28 
29 
rotate3d(yvecs,nmyvtxs,theta,phi,gamma2)30 void      rotate3d(yvecs, nmyvtxs, theta, phi, gamma2)
31 double  **yvecs;		/* ptr to list of y-vectors (to be rotated) */
32 int       nmyvtxs;		/* length of yvecs */
33 double    theta, phi, gamma2;	/* rotational parameters */
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 }
75